Click here to Skip to main content
15,907,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

i have query as
select * from LoginTable where RoleId in ('1','2','3')

i want to pass these parameters via my code,
i don't know how to pass parameter with multiple values please help me with sp also
doing this for the first time your help will be greatly appreciated.

public static DataSet GetLoginInfo(string[] roleid)
     SqlConnection conn = DBConnection.GetConnection();
     SqlCommand cmd = new SqlCommand("GetLoginInfo", conn);
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.Add(new SqlParameter("@roleid", SqlDbType.VarChar)).Value = roleid;

     SqlDataAdapter da = new SqlDataAdapter(cmd);
     DataSet ds = new DataSet();
     catch (Exception) { throw; }
         cmd.Connection = null;
     return ds;
Updated 2-Jun-13 5:52am
Swayam231 31-May-13 3:08am    
how are u providing values to @roleid?? code??
Swayam231 31-May-13 3:24am    
i think this might help:
sql command cmd= new sql command("select * from login where rollid in(@a,@b,@c)",con)
now pass parameters for @a, @b, @c. lyk:
cmd.Parameters.Add("@a", SqlDbType.Int).Value = pid;

let me knw
sunil mali 31-May-13 5:06am    
This will not work as i don't know total parameters. It can be two,three or more than that.
Maciej Los 2-Jun-13 11:53am    
We need to see your stored procedure...

1 solution

Share this answer
Maciej Los 2-Jun-13 11:53am    
Nice link ;)
Zoltán Zörgő 2-Jun-13 16:01pm    
Thanks. Well, why should I repeat myself if the OP does no research at all...?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900