Syntax error in insert into statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gwenne Moses
    New Member
    • Sep 2011
    • 7

    Syntax error in insert into statement

    Hello...
    i am doing some kind of application using Vb.net connected to an access database..unfor tunately i am getting this SYNTAX ERROR IN INSERT INTO STATEMENT...i have been trying to find out y for a day now but i really can't find answers...im feeling sorry for myself now..i am jst a beginner...coul d someone out there pls help me with this..i so much thank you in advance...
    here is my simple code...

    Dim command as New Oledbcommand

    With command
    .Connection = myconnection
    .CommandText = "INSERT INTO tblemployee(Fna me,Mname,Lname, Position,Gender ,Cstatus,Bday,A ge,Address,Tele phone,Cellphone ,Emailaddress,S oftwareknowledg e) VALUES('" & txtFname.Text & "','" & txtmname.Text & "','" & txtLname.Text & "','" & cmbposition.Tex t & "','" & cmbgender.Text & "','" & cmbcstatus.Text & "','" & txtbday.Text & "','" & txtage.Text & "','" & txthome.Text & "','" & txttelephone.Te xt & "','" & txtcp.Text & "','" & txtEmail.Text & "','" & txtswk.Text & "')"
    .ExecuteNonQuer y()
    End With
  • Gwenne Moses
    New Member
    • Sep 2011
    • 7

    #2
    oohh thank u for all those who viewed my Query...
    my program works now...finally found out y...
    tnx much...

    Comment

    • kamellion
      New Member
      • Sep 2011
      • 2

      #3
      Gwenne, consider posting your solution. Others may learn from this, also a solution makes the post complete.

      Regards

      Comment

      • yarbrough40
        Contributor
        • Jun 2009
        • 320

        #4
        Using inline values for insert statements like you are doing here can be dangerous (just fyi). If you are unfamiliar, read up on "sql injection" attacks. Both oledb and sqlconnection methods have parameterized insert options that willwork for your purposes and are much safer.

        Happy coding!

        Comment

        • Gwenne Moses
          New Member
          • Sep 2011
          • 7

          #5
          Okay...
          i jst tried putting brackets [] in my field names n table name..it did work...

          oohh yes..i will..thank u so much!

          Comment

          • yarbrough40
            Contributor
            • Jun 2009
            • 320

            #6
            Can you show examples of what you're trying to do?

            Comment

            • Gwenne Moses
              New Member
              • Sep 2011
              • 7

              #7
              i have a form that is full of textboxes where in the user have to input details or personal info of an employee ..those inputted details r to be saved to an access database...the user should also be able to update n delete records...
              i solved my aforementioned problem by putting brackets with my table name n field names too...this is how i did it...
              "INSERT INTO [tblemployee]([Fname],[Mname],[Lname],[Position],[Gender],[Cstatus],[Bday],[Age],[Address],[Telephone],[Cellphone],[Emailaddress],[Softwareknowled ge]) VALUES('" .........etc... .

              i did put brackets in my update statement too...
              now my whole program works flawlessly...
              tnk u!

              Comment

              Working...