Database update error help

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 5
Reputation: AW08 is an unknown quantity at this point 
Solved Threads: 0
AW08 AW08 is offline Offline
Newbie Poster

Database update error help

 
0
  #1
Nov 18th, 2008
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.

  1. if (Found == "F")
  2. {
  3. if (txtPasswordInput.Text == txtConfirmPassword.Text)
  4. {
  5. DataRow drNewRow = m_dtLoginTable.NewRow(); //creates variable
  6. drNewRow["Username"] = txtUsernameInput.Text;
  7. drNewRow["Password"] = txtPasswordInput.Text;
  8. m_dtLoginTable.Rows.Add(drNewRow);
  9. m_dtDataAdapter.Update(m_dtLoginTable); database
  10. m_rowPosition = m_dtLoginTable.Rows.Count - 1;
  11. new record
  12. }
  13. else
  14. {
  15. txtError.Text = "Passwords do not match";
  16. }
  17.  
  18. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Database update error help

 
0
  #2
Nov 18th, 2008
what is the code for your insert statement? also are you sure you are needing an insert statement here, or an update
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: AW08 is an unknown quantity at this point 
Solved Threads: 0
AW08 AW08 is offline Offline
Newbie Poster

Re: Database update error help

 
0
  #3
Nov 18th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Database update error help

 
0
  #4
Nov 18th, 2008
an insert is a new row, an update is making changes to an existing row

example
  1. INSERT INTO Users (USER_ID, USERNAME, PASSWORD) values (1, 'myusername', 'mypassword')

  1. UPDATE Users set PASSWORD = 'newpassword' WHERE USER_ID = 1
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: AW08 is an unknown quantity at this point 
Solved Threads: 0
AW08 AW08 is offline Offline
Newbie Poster

Re: Database update error help

 
0
  #5
Nov 18th, 2008
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

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

because I just tried that and it didn't work

Thanks for the help.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Database update error help

 
0
  #6
Nov 18th, 2008
the syntax would be

  1. string sql = "INSERT INTO LoginTable (Username, Password) vaues ( \""+ txtUsernameInput.Text + "\", \"" + txtPasswordInput.Text + "\")";
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: AW08 is an unknown quantity at this point 
Solved Threads: 0
AW08 AW08 is offline Offline
Newbie Poster

Re: Database update error help

 
0
  #7
Nov 18th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Database update error help

 
0
  #8
Nov 18th, 2008
but how are inserting the record? calling dataadapter update?

what are the commands that are set for insert, select, and delete on it?
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: AW08 is an unknown quantity at this point 
Solved Threads: 0
AW08 AW08 is offline Offline
Newbie Poster

Re: Database update error help

 
0
  #9
Nov 18th, 2008
I think I've got it working now.

Thanks a lot for your help
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Database update error help

 
0
  #10
Nov 18th, 2008
sure thing, will you post your solution or what you needed to do, so others can learn from this as well
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC