Home > DeveloperSection > Forums > Deleting multiple rows from a table
Aaron Douglas
Aaron Douglas

Total Post:20

Points:140
Posted on    September-28-2013 8:02 AM

 C# C# 
Ratings:


 1 Reply(s)
 579  View(s)
Rate this:

I have a table and I want to delete all rows with a specific card serial . There are multiple rows with the same card serial .So I wrote this code but it seems that's not working:

try
{
using (SqlConnection con = new SqlConnection(WF_AbsPres.Properties.Settings.Default.DbConnectionString))
{
   con.Open();
   SqlCommand command2 = new SqlCommand("DELETE  FORM DevInOut where Cardserial='" + textBox5.Text + "'", con);
   command2.ExecuteNonQuery();
   con.Close();
}
}
   catch (SqlException ex)
{
}

how can assure all the rows will be deleted . Should I use procedure? How do I use procedure?



Madam Walker
Madam Walker

Total Post:22

Points:154
Posted on    September-28-2013 8:59 AM

Hey Aaron!

Change your FORM to FROM.

using (SqlConnection con = new SqlConnection(WF_AbsPres.Properties.Settings.Default.DbConnectionString))
{
   con.Open();
   SqlCommand command2 = new SqlCommand("DELETE FROM DevInOut where Cardserial=@Cardserial", con);
   commdand2.Parameters.AddWithValue("@Cardserial", textBox5.Text);
   command2.ExecuteNonQuery();
   con.Close();
}

Don't want to miss updates? Please click the below button!

Follow MindStick