Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
string cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
            SqlConnection cn = new SqlConnection((cs));
            cn.Open();
   SqlCommand cmd = new SqlCommand("select * from Student_Details where Sid=@Sid", cn);  
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            cmd.ExecuteNonQuery();
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
Posted
Updated 28-Jun-15 21:32pm
v4
Comments
[no name] 29-Jun-15 3:35am    
Please refer to https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters(v=vs.110).aspx to understand properly on how to pass parameters to SqlCommand.
I am sure this will give you clear understanding and help you to solve your problem yourself.

1 solution

You have forgetten to add parameter value before excuting the command.
C#
SqlCommand cmd = new SqlCommand("select * from Student_Details where Sid=@Sid", cn);  
cmd.Parameters.AddWithValue("@Sid", sid);// where sid is the value for parameter @Sid


Hope it helps :)
 
Share this answer
 
Comments
Member 11782598 29-Jun-15 3:38am    
I tried like that also with cmd.parameters command. but i'm not getting any grid view after compiling,just displaying a label which i mentioned for heading to that grid, and not getting any error.

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