I wrote a code to add row that getting the values from textboxes
i wrote a code but it doesn’t work propatly.
when Idebugg it i get this error:”Syntax error in the INSERT INTO command”
i don’t know how to make it works.
Heres the code:
private void addRow_Click(object sender, EventArgs e)
{
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Projects_2012\\Project_Noam\\Access\\myProject.accdb";
OleDbConnection myConnection = new OleDbConnection(connectionString);
string myAddingQuery = string.Format("insert into tblCodons(codonsCodon1, codonsCodon3, " +
"codonsTriplet1, codonsTriplet2, codonsTriplet3, codonsTriplet4, " +
"codonsTriplet5, codonsTriplet6, codonsFullName" +
") values ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8})",
codon1.Text, codon3.Text, triplet1.Text, triplet2.Text,
triplet3.Text, triplet4.Text, triplet5.Text, triplet6.Text,
fullName.Text);
OleDbCommand myCommand = new OleDbCommand(myAddingQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
}
TNX to the helpers!
It’s probably complaining because you’re not quoting any of the values. However, you shouldn’t be including the values directly in the SQL anyway – you should use a parameterized statement. That way:
See the docs for
OleDbCommand.Parametersfor a full example. Your code would probably become something like: