Syntax error in INSERT INTO statement

SteamTank

New Member
I'm having a problem that I'm sure is being caused by a rookie error. I've written some code that is supposed to take a user registration form and insert it into a dbase. The page loads fine and when I hit "submit" I get a "Syntax error in INSERT INTO statement" error. Here's the code:<BR><BR>sub Button1_Click(obj as object, e as EventArgs)<BR> if Page.IsValid then<BR> dim ds as new Dataset ("ds_users")<BR> dim objcmd2 as new OleDbDataAdapter ("select * from gd_user", myconn)<BR> dim objAutoGen as new OleDbCommandBuilder(objcmd2) <BR> objcmd2.Fill(ds, "gd_user")<BR> dim dr as datarow = ds.tables("gd_user").newrow()<BR> dr(0) = user.text<BR> dr(1) = password.text<BR> dr(2) = company.text<BR> dr(3) = first_name.text<BR> dr(4) = last_name.text<BR> dr(5) = email.text<BR> dr(6) = bill_address1.text<BR> dr(7) = bill_address2.text<BR> dr(8) = bill_city.text<BR> dr(9) = bill_state.selecteditem.text<BR> dr(10) = bill_province.text<BR> dr(11) = bill_zip.text<BR> dr(12) = bill_country.selecteditem.text<BR> dr(13) = bill_areacode.text<BR> dr(14) = bill_phone1.text<BR> dr(15) = bill_phone2.text<BR> dr(16) = bill_address1.text<BR> dr(17) = bill_address2.text<BR> dr(18) = bill_city.text<BR> dr(19) = bill_state.selecteditem.text<BR> dr(20) = bill_province.text<BR> dr(21) = bill_zip.text<BR> dr(22) = bill_country.selecteditem.text<BR> dr(23) = bill_areacode.text<BR> dr(24) = bill_phone1.text<BR> dr(25) = bill_phone2.text<BR> dr(26) = cc_name.text<BR> dr(27) = cc_type.selecteditem.text<BR> dr(28) = cc_number.text<BR> dr(29) = cc_ccv.text<BR> dr(30) = cc_month.selecteditem.text<BR> dr(31) = cc_year.selecteditem.text<BR> ds.tables("gd_user").rows.add(dr) <BR> <BR> objcmd2.update(ds,"gd_user")<BR> <BR> label1.Text= user.text<BR> end if<BR> end sub<BR><BR>I establish the connection outside of this sub and the connection appears to be fine because I was able to write some manual inserts. Let me know. Thnaks you very much.Forget the first question - I figured it out. Which leads to a second question. The issue was with the "Password" field. Every time I include that field in the insert it breaks. I made sure the data types match. Cold the validation controls effect the insert statement?There are a number of "reserved" words in .Net and it gets very sensitive when you try to use them for something else.<BR><BR>I have gottne the syntax error in insert statement several times and always track it down to the use of a reserved word as a field name. For example a data field named "Date" causes an error as does "Password".<BR><BR>With so many reserved words, I finally just went to a convention where I name all my fields with a one-character prefix<BR>(ie. rDate, rPassword). It's a quick way to avoid the reserved word issue altogether.<BR><BR>Good Luck<BR><BR>Tom TI'm not sure if you're using Access, but it doesn't let you have a field called 'Password'<BR><BR>John
 
Back
Top