Clear Your History from Database in Window Form

This blog defines code to clear your history from database in window form.

private void delete_btn_Click(object sender, EventArgs e)
{
    if (!(textBox1.Text == string.Empty && textBox2.Text == string.Empty))
    {
        string str = "server = MUNESH;Database=data;UID=sa;Password=reladmin";
        SqlConnection con = new SqlConnection(str);
        string query = "Delete from registration where ID= '" + this.textBox1.Text + "' and Password = '" + this.textBox2.Text + "'";
        SqlCommand cmd = new SqlCommand(query, con);
        SqlDataReader myreader;
        try
        {
          con.Open();
          myreader = cmd.ExecuteReader();
          MessageBox.Show("Deleted", "user information");
          while (myreader.Read())
          {
          }
          con.Close();
       }
       catch (Exception ec)
       {
         MessageBox.Show(ec.Message);
       }
    }
    else
    {
         MessageBox.Show("enter ID or password which you want to delete");
    }
}
Ebook Download
View all
Learn
View all