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.

VulpesPosted Jul 7, 2014, 5:41 AM
Anyway glad you've figured it out now :)
Joe WilsonPosted Jul 7, 2014, 4:35 AM
I just change Last Name to LastName in
' "LastName ='" + this.LastName + " ';
VulpesPosted Jul 6, 2014, 3:53 PM
What are the types of each of your columns in the Access database?
Joe WilsonPosted Jul 6, 2014, 2:31 PM
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.
VulpesPosted Jul 6, 2014, 11:00 AM
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 WilsonPosted Jul 6, 2014, 9:24 AM
What should I do?
Khan Abrar AhmedPosted Jul 6, 2014, 5:28 AM
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 WilsonPosted Jul 6, 2014, 4:46 AM
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 WilsonPosted Jul 6, 2014, 4:39 AM
Khan Abrar AhmedPosted Jul 6, 2014, 3:14 AM
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 + "");
}
Sai SherlekarPosted Jul 6, 2014, 2:11 AM
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 WilsonPosted Jul 6, 2014, 1:29 AM
Ranjit PowarPosted Jul 5, 2014, 10:52 AM
{
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);
}