Syntax Error in INSERT INTO Oledb command in C# winforms

1

The whole idea is that I have a register form and after filling all fields with data(Username, Email and Password) and press the Register button to insert this data into my Access database and make a new record but when i try to do so it show Syntax INSERT INTO Error.

Here is the database insert code:

OleDbCommand command = new OleDbCommand();

                command.CommandType = System.Data.CommandType.Text;


                command.CommandText = "INSERT INTO Users (Username, Email, 
Password)" + " VALUES (@Username,@Email,@Password)";
                command.Parameters.AddWithValue("@Username", 
regUsername.Text);
                command.Parameters.AddWithValue("@Email", regEmail.Text);
                command.Parameters.AddWithValue("@Password", 
regPassword.Text);

                command.Connection = dbConnection;

                dbConnection.Open();

                command.ExecuteNonQuery();

                dbConnection.Close();

And here is the exception:

************* Exception Text **************

System.Data.OleDb.OleDbException (0x80040E14): Syntax error in INSERT INTO statement. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS enter code heredbParams, 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 uLock.Register_Design.label1_Click(Object sender, EventArgs e) in C:\Users\NyonBG\Desktop\uLock\uLock\Register Design.cs:line 200 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Label.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

c#
winforms
oledb
oledbcommand
oledbexception
asked on Stack Overflow Oct 23, 2018 by Nyon • edited Oct 23, 2018 by Ashkan Mobayen Khiabani

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0