inserting datagridview rows in database(windows application)
-
Hi, iam doing windows application with c#.. i have to insert datagridview rows into database... with my code data is inserting into database and at the same time it is giving error ("unhandled datatype mismatch") i check with all my database datatypes and text what iam typing. so please provide some help.. mycode is string connection = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source= D:\inventory\management\management\database\muralicell.mdb"; OleDbConnection myconnection = new OleDbConnection(connection); myconnection.Open(); for (int i = 0; i < inwardgrid.Rows.Count; i++) { string insproducts = "INSERT INTO product_details(productid,Invoice_number,productname,units,received_date)VALUES('" + inwardgrid.Rows[i].Cells[0].Value + "','" + inwardinvno.Text + "','" + inwardgrid.Rows[i].Cells[1].Value + "','" + inwardgrid.Rows[i].Cells[2].Value + "','" + inwardrecdate.Text + "')"; OleDbCommand insprocommand = new OleDbCommand(insproducts, myconnection); insprocommand.ExecuteNonQuery(); insprocommand.Dispose(); } myconnection.Close();
murali krishna
-
Hi, iam doing windows application with c#.. i have to insert datagridview rows into database... with my code data is inserting into database and at the same time it is giving error ("unhandled datatype mismatch") i check with all my database datatypes and text what iam typing. so please provide some help.. mycode is string connection = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source= D:\inventory\management\management\database\muralicell.mdb"; OleDbConnection myconnection = new OleDbConnection(connection); myconnection.Open(); for (int i = 0; i < inwardgrid.Rows.Count; i++) { string insproducts = "INSERT INTO product_details(productid,Invoice_number,productname,units,received_date)VALUES('" + inwardgrid.Rows[i].Cells[0].Value + "','" + inwardinvno.Text + "','" + inwardgrid.Rows[i].Cells[1].Value + "','" + inwardgrid.Rows[i].Cells[2].Value + "','" + inwardrecdate.Text + "')"; OleDbCommand insprocommand = new OleDbCommand(insproducts, myconnection); insprocommand.ExecuteNonQuery(); insprocommand.Dispose(); } myconnection.Close();
murali krishna
Hi, Just try to put your code in try & catch block. Because you are getting datatype mismatch error. The conflict is between the data you are passing and the data-type of the fields in database. May be error is due to date field.
Regards, Ujjaval Modi