Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hay the Im still working on the acces database app and I have a little yet frustating problem with the UPDATE command :

C#
 OleDbDataAdapter ap =  new OleDbDataAdapter();
 methods m = new methods();
 OleDbCommand c;

string command = ("UPDATE Users SET Id = ?, User = ? WHERE Id = ?");
            c = new OleDbCommand(command, con);
            c.Parameters.Add(password, OleDbType.VarChar, 14, password);
            c.Parameters.Add(user, OleDbType.VarChar, 25, user);
            c.Parameters.Add(Opassword, OleDbType.VarChar, 14, user);
ap.UpdateCommand = c;
            con.ConnectionString = conection;
            con.Open();
            ap.UpdateCommand.ExecuteNonQuery();

CON is the database connection(its already done), Im trying to connect to a ACCESS database .mdb

Igot the SYNTAX ON UPDATE COMMAND error
Posted
Updated 17-Jan-12 16:28pm
v3

User is a keyword. [User] is what you are looking for. It's a good practice to surround table/field names with []
 
Share this answer
 
Comments
Member 8437747 18-Jan-12 18:41pm    
Id is a field to may I use the "[]" on Id to?
I forget the last field WHERE Id = ? is the olda Id
loctrice 18-Jan-12 19:29pm    
yeah. I usually wrap them all in those.
UPDATE [Users] SET [ID] = ?, [User] = ? WHERE [ID] = ?
Member 8437747 18-Jan-12 19:07pm    
I get that the Id parameter hasnt a predetermined value
loctrice 18-Jan-12 19:30pm    
Yes, if you have id as an auto increment field in your design, then it's best to let it auto increment.
Member 8437747 20-Jan-12 18:36pm    
OK, it helped a bit, Im over it already but I had an error sayng some parameters have not been filled with essential info, I have the code like this:
string command = ("UPDATE Users SET [@Id] = "+password+", [@User] = "+user+" WHERE [@Id] = "+Opassword);

but all the specified parameters are already there, whats rong?
Hi,
Try this

OleDbDataAdapter ap =  new OleDbDataAdapter();
methods m = new methods();
OleDbCommand c;

string command = ("UPDATE Users SET Id = @id, User = @user WHERE Id = @id");
c = new OleDbCommand(command, con);
c.Parameters.Add("@id", OleDbType.VarChar, 14, "<id>");
c.Parameters.Add("@user", OleDbType.VarChar, 25, "<user>");
ap.UpdateCommand = c;
con.ConnectionString = conection;
con.Open();
ap.UpdateCommand.ExecuteNonQuery();
 
Share this answer
 
v3
Comments
Member 8437747 18-Jan-12 18:42pm    
the WHERE Id = ? command refers to the old Id how would the syntax be?
Member 8437747 18-Jan-12 19:07pm    
I get that the Id parameter hasnt a predetermined value
[no name] 18-Jan-12 21:54pm    
OleDbDataAdapter ap = new OleDbDataAdapter();
methods m = new methods();
OleDbCommand c;

string command = ("UPDATE Users SET Id = @id, User = @user WHERE Id = @oid");
c = new OleDbCommand(command, con);
c.Parameters.Add("@id", OleDbType.VarChar, 14, "<id>");
c.Parameters.Add("@user", OleDbType.VarChar, 25, "<user>");
c.Parameters.Add("@oid", OleDbType.VarChar, 25, "<old id>");
ap.UpdateCommand = c;
con.ConnectionString = conection;
con.Open();
ap.UpdateCommand.ExecuteNonQuery();
Member 8437747 20-Jan-12 18:36pm    
OK, it helped a bit, Im over it already but I had an error sayng some parameters have not been filled with essential info, I have the code like this:
string command = ("UPDATE Users SET [@Id] = "+password+", [@User] = "+user+" WHERE [@Id] = "+Opassword);

but all the specified parameters are already there, whats rong?

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