Goran Bibic

Goran Bibic

  • 480
  • 2.9k
  • 200.7k

What is wrong here?

Jan 24 2018 3:11 PM
private void delete_button4_Click(object sender, EventArgs e)
{
if (bar_code1DataGridView.SelectedRows.Count > 0)
{
DataGridViewRow dr = bar_code1DataGridView.SelectedRows[0];
if (string.IsNullOrEmpty(dr.Cells["id"].Value.ToString()))
{
String cs = "Data Source=.\\SQLEXPRESS;Initial Catalog=barcode;Integrated Security=True";
using (SqlConnection openCon = new SqlConnection(cs))
{
using (SqlCommand querySaveStaff = new SqlCommand("DELETE FROM bar_code1 WHERE id=@id", openCon))
{
// querySaveStaff.Parameters.Add("@id",SqlDbType.Int).Value=idTextBox.Text;
querySaveStaff.Parameters.AddWithValue("@id", 1);
openCon.Open();
querySaveStaff.ExecuteNonQuery();
openCon.Close();
}
}
using (SqlConnection openCon = new SqlConnection(cs))
{
string saveStaff = "SELECT * FROM dbo.bar_code1 ";
openCon.Open();
using (SqlDataAdapter querySaveStaff = new SqlDataAdapter(saveStaff, cs))
{
querySaveStaff.Fill(barcodeDataSet.bar_code1);
bar_code1DataGridView.DataSource = barcodeDataSet.bar_code1;
bar_code1DataGridView.Update();
bar_code1DataGridView.Refresh();
}
}
}
}
}

Answers (5)