DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   Database update error help (http://www.daniweb.com/forums/thread158053.html)

AW08 Nov 18th, 2008 9:08 am
Database update error help
 
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";
}

}

dickersonka Nov 18th, 2008 9:51 am
Re: Database update error help
 
what is the code for your insert statement? also are you sure you are needing an insert statement here, or an update

AW08 Nov 18th, 2008 12:39 pm
Re: Database update error help
 
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

dickersonka Nov 18th, 2008 12:46 pm
Re: Database update error help
 
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

AW08 Nov 18th, 2008 12:59 pm
Re: Database update error help
 
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.

dickersonka Nov 18th, 2008 1:03 pm
Re: Database update error help
 
the syntax would be

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

AW08 Nov 18th, 2008 1:08 pm
Re: Database update error help
 
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

dickersonka Nov 18th, 2008 1:10 pm
Re: Database update error help
 
but how are inserting the record? calling dataadapter update?

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

AW08 Nov 18th, 2008 1:17 pm
Re: Database update error help
 
I think I've got it working now.

Thanks a lot for your help

dickersonka Nov 18th, 2008 1:37 pm
Re: Database update error help
 
sure thing, will you post your solution or what you needed to do, so others can learn from this as well


All times are GMT -4. The time now is 2:51 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC