2
votes

I am trying to automatically insert numbers in my MS Access db .

Currently i have a db that looks like:

| id | username | password | name | email |

where id is auto incremented.

And I have this code:

cmd.Parameters.AddWithValue("@userName", tbUname.Text.Trim());
cmd.Parameters.AddWithValue("@password", tbPass.Text.Trim());
cmd.Parameters.AddWithValue("@Name", tbName.Text.Trim());
cmd.Parameters.AddWithValue("@Email", tbEmail.Text.Trim());
string sql = "insert into users " +
            "values('',@userName, @password, @Name, @Email)";

I have tried doing this:

INSERT INTO users (username,password,name,email) VALUES (@userName,@password, @Name, @Email)

the error i get when u run this query is :

System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at Default2.btsignup_Click(Object sender, EventArgs e)

But it doesn't work. I need it so that whenever a new user registers, a number is assigned to them.

Can some one help me out?

1
Do not store passwords in plain text. - SLaks
What error do you get? - SLaks
its just an example please answer the question being asked :) - Craftx398
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandl ...thats the error when i try using the second commad - Craftx398
Can you edit your question to show the full stack trace. The above comment is cut off - Alex

1 Answers

1
votes

I'm gonna take a punt that password is a reserved field name within MS Access

try

cmd.Parameters.AddWithValue("@userName", tbUname.Text.Trim());
cmd.Parameters.AddWithValue("@password", tbPass.Text.Trim());
cmd.Parameters.AddWithValue("@Name", tbName.Text.Trim());
cmd.Parameters.AddWithValue("@Email", tbEmail.Text.Trim());
string sql = "INSERT INTO users (username,[password],name,email) VALUES (@userName,@password, @Name, @Email)";

note the [ ] around password