Sunday, September 3, 2017

C# Windows application search

In our previous lesson, You learn that how to update data from SQL server by c# windows application. In this lesson, we learn how to search that data.

First, add button from Toolbox and name it to search, that you learn from the first lesson

Then click button search and paste this code.  

   private void button5_Click(object sender, EventArgs e)
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select * from yy  where id ='" + textBox3.Text + "'";

            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            dataGridView1.DataSource = dt;

Then we save the code.Now click on start for execute the code. 

Now write down the id you want to search and press the search button.

No comments:

Post a Comment