The Error:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Syntax error in UPDATE statement.
Additional information: Syntax error in UPDATE statement.
My code:
public void Edit()
{
Connection C2 = new Connection();
C2.SetData("update Student set Student_Number = " + this.Student_Number + ", Name = '" + this.Name + "', Last Name = " + this.LastName + "',Field = " + this.Field + "',Average=" + this.Average + " where Student_Number = " + this.Student_Number + "',Student_ID=" + this.Student_ID + "");
}
{
Connection C2 = new Connection();
C2.SetData("update Student set Student_Number = " + this.Student_Number + ", Name = '" + this.Name + "', Last Name = " + this.LastName + "',Field = " + this.Field + "',Average=" + this.Average + " where Student_Number = " + this.Student_Number + "',Student_ID=" + this.Student_ID + "");
}
Please Help me solve my problem.


Khan Abrar AhmedRank #778 · 3K reputationPosted Jul 5, 2014, 11:14 PM EDT
public void Edit()
{
Connection C2 = new Connection();
C2.SetData("update Student set Student_Number = " + this.Student_Number + ", Name = '" + this.Name + "', Last Name = '" + this.LastName + "',Field = '" + this.Field + "',Average=" + this.Average + " where Student_Number = '" + this.Student_Number + "',Student_ID=" + this.Student_ID + "");
}
Khan Abrar AhmedRank #778 · 3K reputationPosted Jul 6, 2014, 1:28 AM EDT
C2.SetData("update Student set Student_Number = " + this.Student_Number + ", Name = '" + this.Name + "', Last Name = '" + this.LastName + "',Field = '" + this.Field + "',Average=" + this.Average + " where Student_Number = '" + this.Student_Number + "',Student_ID=" + this.Student_ID + "");
VulpesRank #55 · 29.2K reputationPosted Jul 6, 2014, 11:53 AM EDT
What are the types of each of your columns in the Access database?
Ranjit PowarRank #553 · 4.4K reputationPosted Jul 5, 2014, 6:52 AM EDT
{
Connection C2 = new Connection();
C2.SetData("update Student set Student_Number = " + this.Student_Number + ", Name = '" + this.Name + "', Last Name = '" + this.LastName + "',Field ='" + this.Field + "',Average=" + this.Average + " where Student_Number = " + this.Student_Number + ",Student_ID=" + this.Student_ID);
}
Joe WilsonRank #631 · 3.8K reputationPosted Jul 5, 2014, 9:29 PM EDT
Sai SherlekarRank #1,392 · 1.2K reputationPosted Jul 5, 2014, 10:11 PM EDT
for that just use simple statement
like
update student set Name='abc' where Student_Number = 123
means use hard coded value and try simple statements without concatenation.
Joe WilsonRank #631 · 3.8K reputationPosted Jul 6, 2014, 12:39 AM EDT
Joe WilsonRank #631 · 3.8K reputationPosted Jul 6, 2014, 12:46 AM EDT
What is my code problem?
Please guide me.
My code:
public void SetData(string s2)
{
OleDbConnection CN = new OleDbConnection();
CN.ConnectionString = "provider = microsoft.Ace.oledb.12.0; Data source = D:\\Database 10.accdb";
CN.Open();
OleDbCommand cmd = new OleDbCommand(s2, CN);
cmd.ExecuteNonQuery();
CN.Close();
}
Joe WilsonRank #631 · 3.8K reputationPosted Jul 6, 2014, 5:24 AM EDT
What should I do?
VulpesRank #55 · 29.2K reputationPosted Jul 6, 2014, 7:00 AM EDT
You also have unbalanced single quotes around some of your string columns.
Finally you can join two conditions in a WHERE clause with the AND operator.
So I'd try this (I'm guessing that Student_ID is an integer rather than a string):
public void Edit()
{
Connection C2 = new Connection();
C2.SetData("update Student set Student_Number = " + this.Student_Number + ", [Name] = '" + this.Name + "', Last Name = '" + this.LastName + "', [Field] = '" + this.Field + "', Average = " + this.Average + " where Student_Number = " + this.Student_Number + " and Student_ID = " + this.Student_ID);
}
Joe WilsonRank #631 · 3.8K reputationPosted Jul 6, 2014, 10:31 AM EDT
The arrangements of editing is important?
because in data grid view The arrangements is (Code,Name,Last Name,Field,Average,Student Number,student ID)
So Do you think I must change the arguments arrangements in order to don't receive that error.
Joe WilsonRank #631 · 3.8K reputationPosted Jul 7, 2014, 12:35 AM EDT
I just change Last Name to LastName in
' "LastName ='" + this.LastName + " ';
VulpesRank #55 · 29.2K reputationPosted Jul 7, 2014, 1:41 AM EDT
Anyway glad you've figured it out now :)