Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 can't get the result from stored procedure

Author  Topic 

guptaalok12
Starting Member

5 Posts

Posted - 2009-09-15 : 03:09:14

i am passing values to stored procedure from .net through command parameters.when i pass values like

string City="'Lucknow','Kanpur'";
Com.Parameter.AddWithValues("@Cities",City);


create procedure SPGetState
@Cities varchar(2000)
As
Select * from Temp Where City in(@Cities)

i can't get the result.But i run this in Sql Query Analyzer ,i get the result.What;s the problem,i can't find................

alokgupta

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2009-09-15 : 07:08:09
Have a look for a function to convert a delimited string into a table, e.g.
http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm

When this query is run in SQL Server it looks like this:
Select * from Temp Where City in("'Lucknow','Kanpur'")
And because there is no city called by that entire string, it returns nothing.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-15 : 08:26:03
Also search for Array+SQL Server in google

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2009-09-15 : 13:29:48
More like this


string City="'Lucknow','Kanpur'";

command.Parameters.Add(new SqlParameter("@city", SqlDbType.NVarChar, 256));

command.Parameters[0].Value = City;

Go to Top of Page
   

- Advertisement -