I have designed the database in which there are two columns named Class and roll no. Now I want to retrieve all the roll no with a specific class. i will enter the class in the textbox and will press the button.I expect that all the Records which satisfy my query must be displayed in data grid view.
i have written the following code for the above but it has some error.
TypeScript |
if anybody can find out the problem in my prog. or has some different to my solution please reply as soon as possible.
thanks in advance.

Satyapriya NayakRank #47 · 31.5K reputationPosted Jun 12, 2010, 8:25 PM EDT
Here is the code:-
Note:- See the bold part of the code.
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from student where Class='" +TextBox1.Text+ "'";
cmd = new SqlCommand(str,con);
ad = new SqlDataAdapter(cmd);
ds = new DataSet();
ad.Fill(ds,"student");
dataGridView1.DataMember = "student";
dataGridView1.DataSource = ds;
con.Close();
Thanks
If it helps you plz mark it as Accepted Answer
}