Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
foreach (GridViewRow g1 in GridView1.Rows)
{
OleDbCommand oleDbCmd4 = con.CreateCommand();
con.Open();
oleDbCmd4 = new OleDbCommand("INSERT INTO [Article of clients (step)] (CodArt, NumFas, CodPie,Operac, FasExt, CodMaq,CodUti, TiePre, TieFab, CodPro, Control) VALUES (@one,@two,@three,@four,@five,@six,@seven,@eight,@nine,@ten,@eleven)", con);
oleDbCmd4.Parameters.AddWithValue("@one", g1.Cells[0].Text);
oleDbCmd4.Parameters.AddWithValue("@two", g1.Cells[1].Text);
oleDbCmd4.Parameters.AddWithValue("@three", g1.Cells[2].Text);
oleDbCmd4.Parameters.AddWithValue("@four", g1.Cells[3].Text);
oleDbCmd4.Parameters.AddWithValue("@five", g1.Cells[4].Text);
oleDbCmd4.Parameters.AddWithValue("@six", g1.Cells[5].Text);
oleDbCmd4.Parameters.AddWithValue("@seven", g1.Cells[6].Text);
oleDbCmd4.Parameters.AddWithValue("@eight", g1.Cells[7].Text);
oleDbCmd4.Parameters.AddWithValue("@nine", g1.Cells[8].Text);
oleDbCmd4.Parameters.AddWithValue("@ten", g1.Cells[9].Text);
oleDbCmd4.Parameters.AddWithValue("@eleven", g1.Cells[10].Text);
oleDbCmd4.ExecuteNonQuery();
con.Close();
}

What I have tried:

Plz help. I have tried alot but it throw me this error Data type mismatch in criteria expression.
Posted
Updated 18-Jan-17 19:15pm
Comments
[no name] 18-Jan-17 11:56am    
What is that you think we can tell you? Go look at your database and see which part of your data doesn't match the data type. We can't tell you anything more than the error message.
Richard Deeming 18-Jan-17 15:25pm    
REPOST
This is exactly the same question you posted yesterday:
https://www.codeproject.com/Questions/1166111/Syntax-error-missing-operator-in-query-expression[^]

If you want to update your question, click the green "Improve question" button. DO NOT post your update as a new question.

We can't help you specifically, we have no idea what is in the GridView cells, or what datatypes your DB is expecting.

Most likely, the DB is expecting a number or a Date, and you are supplying a string. I'd suggest that you cast or parse each cell to the appropriate C# variable type and pass that instead - at least that way you should find any problem and the cell it is in.
 
Share this answer
 
Comments
Maciej Los 18-Jan-17 16:04pm    
Couldn't say it better!
Please check the data type of the table column which your are used for pushing the data from the table.
Ex: If your column datatype is integer but you are trying to push a string variable then it will throw datatype mismatch.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900