Sunday, September 3, 2017

C# Windows application delete

In our previous lesson, You learn that how to view data from sql server by c# windows application. In this lesson, we learn how to delete or omit that data.

First add button delete and Textbox from Toolbox, that you learn from the first lesson.   














Then click button view and paste this code.

    private void button3_Click(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "delete from yy where id='" + textBox3.Text + "'";
            cmd.ExecuteNonQuery();
            con.Close();
            display();
            MessageBox.Show("Delete Successful");
        }   

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















Now write down the id you want to delete.press the delete button.














Data is deleted. Please share if you like my article.

No comments:

Post a Comment