Need help with Saving Info into Database!

Wait, wait wait wait!!

Newsflash: IT WORKS
:)

It did end up being the Password Field, I simply changed it to "PW" and it works like a charm.

Thanks for the help everyone, I may be back with more questions :)
 
Ah, whew.

Well, the alternative is to NOT use the CommandBuilder (its kind of a beginners helper class more than anything). You can use the CommandBuilder while in development, but look at the SQL string it builds for you (the CommandText property as I mentioned above). Once you have the INSERT string that the CommandBuilder built for you, you can do away with the CommandBuilder and hard-code the string for yourself.

It will mean manually updating the string as your database changes. But, it also gives you more controls over the SQL youre using. For example, the default SQL might look like:
Code:
INSERT INTO TABLE1 (ID, Username, Password) VALUES (?, ?, ?)

As youve seen, this wont work since Password is a reserved word. Instead, replace the string with:
Code:
INSERT INTO TABLE1 ([ID], [Username], [Password]) VALUES (?, ?, ?)

Notice the square brackets. You can *always* use square brackets on column names. If you ever forget and your column is a reserved word, you just might get this exception again. For example, "id" is a reserved word in SQL Server... Better safe than sorry and use the square brackets and NOT use the CommandBuilder.

-Nerseus
 
Originally posted by Nerseus
Ah, whew.

Well, the alternative is to NOT use the CommandBuilder (its kind of a beginners helper class more than anything). You can use the CommandBuilder while in development, but look at the SQL string it builds for you (the CommandText property as I mentioned above). Once you have the INSERT string that the CommandBuilder built for you, you can do away with the CommandBuilder and hard-code the string for yourself.

There is one alternative if you would still prefer to use the commandbuilder: that is to use a QuotePrefix of "[" and QuoteSuffix of "]".

Here is a link to the msdn reference.

-Nate
 
Heh you guys are still responding :)

Well I got an A on my project, an A in the class, and I wont have to worry about VB again for a while (if ever hopefully) :p

Thanks for all your help
 
Back
Top