private void btn_Add_Click(object sender, EventArgs e)
{
for (int i = 0; i < dgv_Add_job_card.Rows.Count ; i++)
{
con.Open();
s = "insert into Auto_Part_Details (Items_No, Job_Card, Value_Part, Auto_Parts_id, Repair_id, New_Old_Part, Provider_id, Installation_id, Notes) values (@Items_No, @Job_Card, @Value_Part,@Auto_Parts_id , @Repair_id,@New_Old_Part , @Provider_id, @Installation_id , @Notes)";
sd=new SqlCommand(s,con);
sd.Parameters.AddWithValue("@Items_No", dgv_Add_job_card.Rows[i].Cells[0].Value);
sd.Parameters.AddWithValue("@Job_Card", dgv_Add_job_card.Rows[i].Cells[1].Value);
sd.Parameters.AddWithValue("@Value_Part", dgv_Add_job_card.Rows[i].Cells[2].Value);
sd.Parameters.AddWithValue("@New_Old_Part", dgv_Add_job_card.Rows[i].Cells[5].Value);
sd.Parameters.AddWithValue("@Notes", dgv_Add_job_card.Rows[i].Cells[7].Value);
sd.Parameters.AddWithValue("@Auto_Parts_id", dgv_Add_job_card.Rows[i].Cells[9].Value);
sd.Parameters.AddWithValue("@Repair_id", dgv_Add_job_card.Rows[i].Cells[10].Value);
sd.Parameters.AddWithValue("@Provider_id", dgv_Add_job_card.Rows[i].Cells[11].Value);
sd.Parameters.AddWithValue("@Installation_id", dgv_Add_job_card.Rows[i].Cells[12].Value);
sd.ExecuteNonQuery();
con.Close();
}
}
this error happened when i change code that retrieve data in combobox :-
void FillComboBoxRepair()
{
try
{
con.Open();
s = "select * from Repair_Type";
sd = new SqlCommand(s,con);
sda = sd.ExecuteReader();
while(sda.Read())
{
string Repair_type = sda.GetString(1);
CB_Repair_type.Items.Add(Repair_type);
}
con.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void FillComboBoxProviders()
{
try
{
con.Open();
s = "select * from Providers";
sd = new SqlCommand(s, con);
sda = sd.ExecuteReader();
while (sda.Read())
{
string Provider_desc = sda.GetString(2);
CB_Providers_desc.Items.Add(Provider_desc);
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}