Saturday, September 2, 2017

C# curd read portion

In our previous lesson, You learn that how to insert data into sql server by c# windows application. In this lesson, we learn how to view that data.

First add button view and DataGridView from Toolbox, that you learn from the previous lesson.

Then click button view and paste this code.Where we call a function name display. 

   private void button2_Click(object sender, EventArgs e)

Then write function and paste the below code.

        private void display()
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select * from yy";

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

Then we save the code.Now click on start for execute the view to show the data it very easy and simple but you have to follow the first lesson.

If you like this article please share.

No comments:

Post a Comment