Hi
I have written query for inserting records in SQL daatbase from datagridview & some comboboxes & textboxes.
But it is given error like null expection was unhandled.
Please help to detect what is wrong in below code.
private void btnsubmit_Click(object sender, EventArgs e)
{
for (int i = 0; i < cnt; i++)
{
String str = "INSERT INTO JOB_Quality_Rating values('" + comboBox1.SelectedItem + "','" + comboBox3.SelectedItem + "','" + textBox1.Text + "','" + cmbtaskno.SelectedItem + "','" + comboBox2.SelectedItem + "','" + dataGridView1.Rows[i].Cells[0].Value.ToString() + "','" + dataGridView1.Rows[i].Cells[1].Value.ToString() + "','" + dataGridView1.Rows[i].Cells[2].Value.ToString() + "','" + txtTotal.Text + "','" + mdlconnection.user_id + "','" + DateTime.Now + "')";
//int d = mdlconnection.excuteQuery(str);
//if (d > 0)
mdlconnection.excuteQuery(str);
{
MessageBox.Show("Job Quality Save sucessfully");
}
}
}
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Nanhe SiddiqueRank #1,103 · 1.7K reputationPosted May 14, 2015, 8:17 PM EDT
https://khanrahim.wordpress.com/2010/04/13/combobox-with-datagridview-in-c/
it may help you
Munesh SharmaRank #174 · 13.9K reputationPosted May 14, 2015, 9:25 PM EDT
or you can write query like
insert into tablename (column name) values (values);