How to Delete Sql server by C# Form?
How to Delete Sql server by C# Form?
{
try
{
con.Open();
string query = "DELETE FROM tbl_CustomersInfo WHERE ID_Customers='" + txtIDCus.Text + "'";
SqlDataAdapter SDA = new SqlDataAdapter(query, con);
SDA.SelectCommand.ExecuteNonQuery();
MessageBox.Show("Deleted!");
string Query = "SELECT * FROM tbl_CustomersInfo";
SqlDataAdapter sda = new SqlDataAdapter(Query, con);
DataTable data = new DataTable();
sda.Fill(data);
dgvCustomerInfo.DataSource = data;
txtIDCus.Text = "";
txtName.Text = "";
cbogander.Text = "";
txtPhone.Text = "";
txtAddress.Text = "";
cboGategory.Text = "";
txtQuatity.Text = "";
txtPrice.Text = "";
txtPayment.Text = "";
txtIDCus.Focus();
}
catch
{
MessageBox.Show("Your Delete error...Please try again!");
}
con.Close();
}
else {
this.Show();
txtIDCus.Text = "";
txtName.Text = "";
cbogander.Text = "";
txtPhone.Text = "";
txtAddress.Text = "";
cboGategory.Text = "";
txtQuatity.Text = "";
txtPrice.Text = "";
txtPayment.Text = "";
txtIDCus.Focus();
}
}
Post a Comment