943,961 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 573
  • C# RSS
Nov 18th, 2008
0

Database update error help

Expand Post »
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.

C# Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AW08 is offline Offline
5 posts
since Nov 2008
Nov 18th, 2008
0

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
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Nov 18th, 2008
0

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AW08 is offline Offline
5 posts
since Nov 2008
Nov 18th, 2008
0

Re: Database update error help

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

example
C# Syntax (Toggle Plain Text)
  1. INSERT INTO Users (USER_ID, USERNAME, PASSWORD) values (1, 'myusername', 'mypassword')

C# Syntax (Toggle Plain Text)
  1. UPDATE Users set PASSWORD = 'newpassword' WHERE USER_ID = 1
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Nov 18th, 2008
0

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

C# Syntax (Toggle Plain Text)
  1. LoginTable("Username","Password") values (txtUsernameInput.Text,txtPasswordInput.Text);

because I just tried that and it didn't work

Thanks for the help.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AW08 is offline Offline
5 posts
since Nov 2008
Nov 18th, 2008
0

Re: Database update error help

the syntax would be

C# Syntax (Toggle Plain Text)
  1. string sql = "INSERT INTO LoginTable (Username, Password) vaues ( \""+ txtUsernameInput.Text + "\", \"" + txtPasswordInput.Text + "\")";
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Nov 18th, 2008
0

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AW08 is offline Offline
5 posts
since Nov 2008
Nov 18th, 2008
0

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?
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Nov 18th, 2008
0

Re: Database update error help

I think I've got it working now.

Thanks a lot for your help
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AW08 is offline Offline
5 posts
since Nov 2008
Nov 18th, 2008
0

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
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: how i can fetch the from datagrid
Next Thread in C# Forum Timeline: TCPClient And TCPServer





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC