private void button3_Click(object sender, EventArgs e) { try { using (var cmd106 = new SqlCommand("select * from [dbo].[incidentNoReserve]", cnn)) { cnn.Open(); SqlDataReader reader = cmd106.ExecuteReader(); while (reader.Read()) { int commonNo = Convert.ToInt16(reader["incidentNoReserveId"]); //Every new row will create a new dictionary that holds the columns if (Convert.ToInt16(commonNo) == newLastIncidentNo) { newLastIncidentNo = (Convert.ToInt16(commonNo)); using (SqlCommand command = new SqlCommand("Delete from[dbo].[incidentNoReserve] where incidentNoReserveId = @newLastIncidentNo", cnn)) { cnn.Open(); command.Parameters.AddWithValue("@newLastIncidentNo", newLastIncidentNo); command.ExecuteNonQuery(); cnn.Close(); } } } reader.Close(); cnn.Close(); } } catch (Exception ex) { //If an exception occurs, write it to the console Console.WriteLine(ex.ToString()); } finally { cnn.Close(); } this.Close(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)