The good thing is that you have got rid of the concatenated text version - that is very dangerous!
The next thing to do is find out when you get "a syntax error" - and I'm guessing it's at runtime not compile time, which means it's a problem with the SQL command.
And that means it's likely to be the named parameters, which an OleDbConnection doesn't support in the same way as an SqlConnection.
Because you name a parameter in your query, but comment it out in your
cmd.Parameters.AddwithValue
list, tejh command processor is probably complainign about the "
<pre>where StudentID=@StudentID</pre>
" becuase
@StudentID
will be replaced with a NULL and that's probably the problem
Uncomment the line, and it should work:
cmd.CommandText = "update product set LastName=@LastName,FirstName=@FirstName,MiddleName=@MiddleName,Section=@Section where StudentID=@StudentID";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@LastName", TextBox1.Text);
cmd.Parameters.AddWithValue("@FirstName", TextBox2.Text);
cmd.Parameters.AddWithValue("@MiddleName", TextBox3.Text);
cmd.Parameters.AddWithValue("@Section", TextBox4.Text);
cmd.Parameters.AddWithValue("@StudentID", TextBox5.Text);
cmd.ExecuteNonQuery();
But do remember that the names are irrelevant in OldDb, and can be replaced with placeholders - the order in which they are added controls where they go!
cmd.CommandText = "UPDATE product SET LastName=@LastName, FirstName=?, MiddleName=?, Section=? WHEREStudentID=?";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@LastName", TextBox1.Text);
cmd.Parameters.AddWithValue("@FirstName", TextBox2.Text);
cmd.Parameters.AddWithValue("@MiddleName", TextBox3.Text);
cmd.Parameters.AddWithValue("@Section", TextBox4.Text);
cmd.Parameters.AddWithValue("@StudentID", TextBox5.Text);
cmd.ExecuteNonQuery();