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
SQL
select * from LoginTable where RoleId in ('1','2','3')


i want to pass these parameters via my asp.net 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.

C#
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();
     try
     {
         conn.Open();
         da.Fill(ds);
     }
     catch (Exception) { throw; }
     finally
     {
         conn.Close();
         cmd.Connection = null;
         cmd.Dispose();
     }
     return ds;
 }
Posted
Updated 2-Jun-13 5:52am
v3
Comments
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
 
Comments
Maciej Los 2-Jun-13 11:53am    
Nice link ;)
+5
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