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 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Munesh SharmaPosted May 15, 2015, 1:25 AM
or you can write query like
insert into tablename (column name) values (values);
Nanhe SiddiquePosted May 15, 2015, 12:17 AM
https://khanrahim.wordpress.com/2010/04/13/combobox-with-datagridview-in-c/
it may help you