I am trying to display the search results I obtain from searching a database in a datagrid control present on my form.
My table name is bookinfo with following columns bid, bname, author, unitprice, availablebooks.
I have a textbox on my windows form and i want to display these search results in datagrid as a textchanged event.
I'm not getting any idea for doing this, Can any body give the sample code or at least give me an idea about writing the steps.
Thank You in advance Guys....
Displaying search results in Datagridview
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Rewant ChoudharyRank #4,270 · 354 reputationPosted Sep 7, 2012, 6:22 AM EDT
myConnection = WebConfigurationManager.ConnectionStrings["onnectionString"].ConnectionString; connect = new SqlConnection(myConnection); command = new SqlCommand(); connect.Open(); command.Connection = connect; string komut = "SELECT * FROM table name WHERE authername='"+textbox1.Text+"'"; try { SqlCommand sqlCommand = new SqlCommand(); sqlCommand = connect.CreateCommand(); sqlCommand.CommandText = komut; SqlDataAdapter sda = new SqlDataAdapter(sqlCommand.CommandText, connect); SqlCommandBuilder scb = new SqlCommandBuilder(sda); //Create a DataTable to hold the query results. DataTable dTable = new DataTable(); //Fill the DataTable. sda.Fill(dTable); GridView1.DataSource = dTable; GridView1.DataBind(); } catch (SqlException) { //Console.WriteLine(e.StackTrace); } reader.Close(); connect.Close();