Goran Bibic

Goran Bibic

  • 482
  • 2.9k
  • 197.8k

What is wrong?

Jan 25 2018 3:53 AM

  1. private void button4_Click(object sender, EventArgs e)  
  2.         {  
  3.             if (bar_code1DataGridView.SelectedRows.Count > 0)  
  4.             {  
  5.   
  6.                 DataGridViewRow dr = bar_code1DataGridView.SelectedRows[0];  
  7.                 if (!string.IsNullOrEmpty(dr.Cells["dataGridViewTextBoxColumn1"].Value.ToString()))  
  8.                 {  
  9.   
  10.                     String cs = "Data Source=.\\SQLEXPRESS;Initial Catalog=barcode;Integrated Security=True";  
  11.                     using (SqlConnection openCon = new SqlConnection(cs))  
  12.                     {  
  13.   
  14.   
  15.                         using (SqlCommand querySaveStaff = new SqlCommand("DELETE FROM bar_code1 WHERE id=@id", openCon))  
  16.                         {  
  17.   
  18.                             // querySaveStaff.Parameters.Add("@id",SqlDbType.Int).Value=idTextBox.Text;  
  19.                             querySaveStaff.Parameters.AddWithValue("@id", 0);  
  20.                               
  21.                             openCon.Open();  
  22.                             querySaveStaff.ExecuteNonQuery();  
  23.                             openCon.Close();  
  24.   
  25.                         }  
  26.   
  27.                     }  
  28.   
  29.                     using (SqlConnection openCon = new SqlConnection(cs))  
  30.   
  31.                     {  
  32.   
  33.                         string saveStaff = "SELECT * FROM dbo.bar_code1 ";  
  34.                         openCon.Open();  
  35.                         using (SqlDataAdapter querySaveStaff = new SqlDataAdapter(saveStaff, cs))  
  36.                         {  
  37.                             querySaveStaff.Fill(barcodeDataSet.bar_code1);  
  38.                             bar_code1DataGridView.DataSource = barcodeDataSet.bar_code1;  
  39.                             bar_code1DataGridView.Update();  
  40.                             bar_code1DataGridView.Refresh();  
  41.                         }  
  42.   
  43.                     }  
  44.                 }  
  45.             }  
  46.         } 

Answers (5)