I'm trying to write a questionnaire that gathers info of the user and then updates a database in Access. I've managed to write the program and everything works up to the point where it updates the database, at which point it displays the error message below:

OleDbException was unhandled
Syntax error in INSERT INTO statement

I've checked it and I can't find any syntax errors in it. Could someone help me out please? I'm very new to programming, so please try to explain in as simple terms as possible. The section of code is below. Thanks for your help.

if (Found == "F")
{
if (txtPasswordInput.Text == txtConfirmPassword.Text)
{
DataRow drNewRow = m_dtLoginTable.NewRow(); //creates variable
drNewRow["Username"] = txtUsernameInput.Text;
drNewRow["Password"] = txtPasswordInput.Text;
m_dtLoginTable.Rows.Add(drNewRow);
m_dtDataAdapter.Update(m_dtLoginTable); database
m_rowPosition = m_dtLoginTable.Rows.Count - 1;
new record
}
else
{
txtError.Text = "Passwords do not match";
}

}

what is the code for your insert statement? also are you sure you are needing an insert statement here, or an update

What's the difference between insert and update (like i said I'm very new to this, please be patient) and which one would I need if I were trying to add a new row to my Access database for each new username created in a Windows form application

an insert is a new row, an update is making changes to an existing row

example

INSERT INTO Users (USER_ID, USERNAME, PASSWORD) values (1, 'myusername', 'mypassword')
UPDATE Users set PASSWORD = 'newpassword' WHERE USER_ID = 1

Sorry to act like such as novice but could you help me with what I would actually write.
I'm trying to insert txt.UsernameInput.Text and txt.PasswordInput.Text into the new row in the Username and Password columns. The name of the table is LoginTable and the name of the Access file is Login. So would I write something like this

LoginTable("Username","Password") values (txtUsernameInput.Text,txtPasswordInput.Text);

because I just tried that and it didn't work

Thanks for the help.

the syntax would be

string sql = "INSERT INTO LoginTable (Username, Password) vaues ( \""+ txtUsernameInput.Text + "\", \"" + txtPasswordInput.Text + "\")";

It seems to work, but I still think I'm doing something wrong, because it seems to work but then when I go back to a different form and try to login in using the username I just created it tells me that it doesn't exist and it's not appearing in the database either

but how are inserting the record? calling dataadapter update?

what are the commands that are set for insert, select, and delete on it?

I think I've got it working now.

Thanks a lot for your help

This article has been dead for over six months. Start a new discussion instead.