|
First, take the square brackets off your stored proc name in the C# code.
Second, put a try/catch block in your c# method so you can see what exception is being thrown. That will tell you exactly what the problem is.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
John,
Thanks for responding to my question.
I'm not getting an error message. The problem is I am not getting any records back.
I previously tried removed the square brackets, but that generated an error that the SP couldn't be found 
|
|
|
|
|
Start by checking that you are testing against the same database - it's surprising how often the SSMS check is done against the production DB instead of the development DB which has different data!
Then check that the SP in your Dev DB looks exactly like you think it does.
If all of that looks good, comment out the content of your SP, and replace it with this:
select '-' + item_id + '-', '-' + @ItemsIDS + '-' from q_Warehouse80_OOS_ItemsNeedingNotification where item_id = 'B30-244-595-CB-B001' Then run your C# code again and see exactly what you get back.
If what you say is right, then it should be two identical strings:
-B30-244-595-CB-B001- and -B30-244-595-CB-B001-
But I'm betting it doesn't. Either way, that should isolate roughly where the problem is being caused - and that should give you (and us) at least more to work from.
I'd code it differently:
cmd = new SqlCommand();
cmd.CommandText = SQL;
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Connection = conn;
var myparams = new SqlParameter("@ItemsIDS", DbType.String);
myparams.Direction = ParameterDirection.Input;
myparams.Size = 40;
myparams.Value = ItemsToBeChecked;
cmd.Parameters.Add(myparams);
Would become:
cmd = new SqlCommand(SQL, conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(@ItemsIDS, ItemsToBeChecked);
It might be worth checking that as well, in case it's a field size mismatch / padding problem.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I modified my SP as you suggested:
BEGIN
SET NOCOUNT ON
--select * from q_Warehouse80_OOS_ItemsNeedingNotification where item_id = @ItemsIDS
select '-' + item_id + '-' as R1, '-' + @ItemsIDS + '-' as R2 from q_Warehouse80_OOS_ItemsNeedingNotification where item_id = 'B30-244-595-CB-B001'
END
And this is what I get back when I call the SP from my C#:
R1 = "-B30-244-595-CB-B001-"
R2 = "-'B30-244-595-CB-B001'-"
|
|
|
|
|
And if you use the debugger to look at your itemsToBeChecked variable in the C#, you'll find the quotes are part of the string - which means they are part of the parameter you pass to SQL, and that explains why it doesn't match.
Now all you need to do is look at where that comes from and find out why the quotes are there. They're easy to get rid of - .Trim('''') will remove them - but it's better to find out what adds them and stop it doing it!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I'm embarrassed to say that my C# code was adding the quotes around the argument being passed because a long time ago(I think it was Monday) I wanted the SP to take a list of strings and check to see if any of them matched the item_ids in the view the SP was searching.
Here is how my SP was originally looking before I started messing with it.
@ItemsIDS AS VARCHAR(max)
AS
BEGIN
SET NOCOUNT ON
select item_id from q_Warehouse80_OOS_ItemsNeedingNotification where item_id in(@ItemsIDS)
END
As you can see I am using the in qualifier which requires the arguments being passed in the @ItemsIDS string to be separated by single quotes.
That's why the quotes were in the argument that I was passing to the SP.
So here I am back to square one trying to figure out why the SP doesn't work when I pass (in this case) one argument in the @ItemsIDS variable.
|
|
|
|
|
Ah. That's simple: the IN part of the SP is precompiled - you can't pass it a list of items in a string, because it doesn't get replaced by the parameter list value.
See here: Using comma separated value parameter strings in SQL IN clauses[^] - it may give you a solution.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
With a slight modification this function works just the way I need it to.
Finally !
Thank you for all your help ! 
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
From you, that is high praise indeed my friend!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
just show me with sample code that how can i call store procedure which return multiple result set with EF code first.
i search google a bit but found no example. thanks
tbhattacharjee
|
|
|
|
|
|
He's the worst example of a Help Vampire I have seen in a long time.
This space for rent
|
|
|
|
|
It'll be fun when he gets to the exams and finds he can't ask anyone at all.
All this lack of effort wasted by a fail! :Evil Smiley:
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Look at his profile. It says he doesn't have time to fill it in. He's obviously not using that time learning the framework.
This space for rent
|
|
|
|
|
suppose i have a store procedure which has one out type parameter and out type parameter value is set inside store proc so when i will call that store proc by EF code first then how could read the out type parameter value by EF code first ?
looking for a small sample. i search google a bit but found no example. thanks
tbhattacharjee
|
|
|
|
|
Might I makes a suggestion: Amazon: Entity Framework[^].
Serisouly, you're not going to learn this stuff by bombarding the forums with questions. You're going to miss a ton of information that ties all this stuff together.
|
|
|
|
|
suppose i am calling store proc by EF code first and store proc return value like this way
select 'SUCCESS'
or
select 1
OR
Return 1
just tell me how to read the single value return by store proc with EF code first. looking for a small sample code. i search google a bit but found no example. thanks
tbhattacharjee
|
|
|
|
|
Tridip Bhattacharjee wrote: i search google a bit but found no example. thanks Really?[^]. They probably aren't all relevant but Google thinks there are 456,000 items that match.
This space for rent
|
|
|
|
|
We've run into a problem where we're getting a Task Canceled Exception. It seems to occur when
code inside a App.Current.Dispatcher.Invoke... gets executed AFTER App.Current.Shutdown is called.
I really don't want to have to check for the app being shutdown every time I do App.Current.Dispatcher.Invoke.
Any way to stop this?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
TaskCancelledException is what is thrown whenever one await a task which is cancelled.
In ContinueWith, however, the Task.Status is cancelled (no exception).
Some system task can, unexpectedly cancel. Find out which task are susceptible to be cancelled and handle the cancellation there. Otherwise it's a legitimate bug.
|
|
|
|
|
please explain that what is difference between LINQ and EF with example. thanks
tbhattacharjee
|
|
|
|
|
Seriously? I just read your question about what the difference is between Agile and Scrum. Have you heard of Google? You have been on this site long enough to know that you should at least think of doing some research beforehand yourself. This is a simple question for you to look up and I would strongly recommend that you learn to do the most basic searches yourself.
This space for rent
|
|
|
|
|
But that would mean doing his own homework...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|