Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. insert syntax problem, pls help....

insert syntax problem, pls help....

Scheduled Pinned Locked Moved Visual Basic
databasehelpdebuggingtutorialquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kyosugi
    wrote on last edited by
    #1

    posted b4 but i cant seem to find the old thread n i need help urgently >.< tis is the code i tried to use --------- Private Sub AddSubmitB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddSubmitB.Click Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Jasmine\db.mdb" Dim cmd As New OleDb.OleDbCommand Dim con As OleDb.OleDbConnection Dim strsql As String con = New OleDb.OleDbConnection(strcon) con.Open() strsql = "Insert into member (BorrowerId, password, MemberType, Fname, Lname, Gender, Address1, Address2, Address3, ContactNo, HandPhNo, Email, CourseOfStudy, EnrolledDate, ExpiryDate) values ('" & StudIdTB.Text & "','" & StudPwTB.Text & "','" & UgTB.Text & "','" & StudFnTB.Text & "','" & StudLnTB.Text & "','" & StudGenderCLB.Text & "','" & StudAdd1TB.Text & "','" & StudAdd2TB.Text & "','" & StudAdd3TB.Text & "','" & StudHmTB.Text & "','" & StudHpTB.Text & "','" & StudMailTB.Text & "','" & CosCB.Text & "','" & EnrolledCB.Text & "','" & ExpiryCB.Text & "')" cmd.Connection = con cmd.CommandText = strsql cmd.ExecuteNonQuery() con.Close() MsgBox("New Member Added!") Me.Close() End Sub --------- when i tested it today, it did not work the debugger stopped at cmd.ExecuteNonQuery it says OleDbException was unhandled Syntax error in INSERT INTO statement. i checked thru my database and the sql statements n r fine, oso tried adding square brackets how to solve?

    N D S 3 Replies Last reply
    0
    • K kyosugi

      posted b4 but i cant seem to find the old thread n i need help urgently >.< tis is the code i tried to use --------- Private Sub AddSubmitB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddSubmitB.Click Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Jasmine\db.mdb" Dim cmd As New OleDb.OleDbCommand Dim con As OleDb.OleDbConnection Dim strsql As String con = New OleDb.OleDbConnection(strcon) con.Open() strsql = "Insert into member (BorrowerId, password, MemberType, Fname, Lname, Gender, Address1, Address2, Address3, ContactNo, HandPhNo, Email, CourseOfStudy, EnrolledDate, ExpiryDate) values ('" & StudIdTB.Text & "','" & StudPwTB.Text & "','" & UgTB.Text & "','" & StudFnTB.Text & "','" & StudLnTB.Text & "','" & StudGenderCLB.Text & "','" & StudAdd1TB.Text & "','" & StudAdd2TB.Text & "','" & StudAdd3TB.Text & "','" & StudHmTB.Text & "','" & StudHpTB.Text & "','" & StudMailTB.Text & "','" & CosCB.Text & "','" & EnrolledCB.Text & "','" & ExpiryCB.Text & "')" cmd.Connection = con cmd.CommandText = strsql cmd.ExecuteNonQuery() con.Close() MsgBox("New Member Added!") Me.Close() End Sub --------- when i tested it today, it did not work the debugger stopped at cmd.ExecuteNonQuery it says OleDbException was unhandled Syntax error in INSERT INTO statement. i checked thru my database and the sql statements n r fine, oso tried adding square brackets how to solve?

      N Offline
      N Offline
      Nouvand
      wrote on last edited by
      #2

      Have you check the concurency?

      1 Reply Last reply
      0
      • K kyosugi

        posted b4 but i cant seem to find the old thread n i need help urgently >.< tis is the code i tried to use --------- Private Sub AddSubmitB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddSubmitB.Click Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Jasmine\db.mdb" Dim cmd As New OleDb.OleDbCommand Dim con As OleDb.OleDbConnection Dim strsql As String con = New OleDb.OleDbConnection(strcon) con.Open() strsql = "Insert into member (BorrowerId, password, MemberType, Fname, Lname, Gender, Address1, Address2, Address3, ContactNo, HandPhNo, Email, CourseOfStudy, EnrolledDate, ExpiryDate) values ('" & StudIdTB.Text & "','" & StudPwTB.Text & "','" & UgTB.Text & "','" & StudFnTB.Text & "','" & StudLnTB.Text & "','" & StudGenderCLB.Text & "','" & StudAdd1TB.Text & "','" & StudAdd2TB.Text & "','" & StudAdd3TB.Text & "','" & StudHmTB.Text & "','" & StudHpTB.Text & "','" & StudMailTB.Text & "','" & CosCB.Text & "','" & EnrolledCB.Text & "','" & ExpiryCB.Text & "')" cmd.Connection = con cmd.CommandText = strsql cmd.ExecuteNonQuery() con.Close() MsgBox("New Member Added!") Me.Close() End Sub --------- when i tested it today, it did not work the debugger stopped at cmd.ExecuteNonQuery it says OleDbException was unhandled Syntax error in INSERT INTO statement. i checked thru my database and the sql statements n r fine, oso tried adding square brackets how to solve?

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        Your old post is here[^], along with my reply to it.

        Dave Kreskowiak Microsoft MVP - Visual Basic

        K 1 Reply Last reply
        0
        • D Dave Kreskowiak

          Your old post is here[^], along with my reply to it.

          Dave Kreskowiak Microsoft MVP - Visual Basic

          K Offline
          K Offline
          kyosugi
          wrote on last edited by
          #4

          opps, thx mus haf posted help at too many forums, missed out, haha

          1 Reply Last reply
          0
          • K kyosugi

            posted b4 but i cant seem to find the old thread n i need help urgently >.< tis is the code i tried to use --------- Private Sub AddSubmitB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddSubmitB.Click Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Jasmine\db.mdb" Dim cmd As New OleDb.OleDbCommand Dim con As OleDb.OleDbConnection Dim strsql As String con = New OleDb.OleDbConnection(strcon) con.Open() strsql = "Insert into member (BorrowerId, password, MemberType, Fname, Lname, Gender, Address1, Address2, Address3, ContactNo, HandPhNo, Email, CourseOfStudy, EnrolledDate, ExpiryDate) values ('" & StudIdTB.Text & "','" & StudPwTB.Text & "','" & UgTB.Text & "','" & StudFnTB.Text & "','" & StudLnTB.Text & "','" & StudGenderCLB.Text & "','" & StudAdd1TB.Text & "','" & StudAdd2TB.Text & "','" & StudAdd3TB.Text & "','" & StudHmTB.Text & "','" & StudHpTB.Text & "','" & StudMailTB.Text & "','" & CosCB.Text & "','" & EnrolledCB.Text & "','" & ExpiryCB.Text & "')" cmd.Connection = con cmd.CommandText = strsql cmd.ExecuteNonQuery() con.Close() MsgBox("New Member Added!") Me.Close() End Sub --------- when i tested it today, it did not work the debugger stopped at cmd.ExecuteNonQuery it says OleDbException was unhandled Syntax error in INSERT INTO statement. i checked thru my database and the sql statements n r fine, oso tried adding square brackets how to solve?

            S Offline
            S Offline
            Stephen McGuire
            wrote on last edited by
            #5

            You have single quotes inside your double quotes. You should only include these for 'string' values. Numbers should not have single quotes. Additionally, 'Date' fields may need octothorpes (#) instead of single quotes. Your commands are setup a little inefficiently. You should only keep a connection open for the shortest time possible. Do everything else first, then open the connection just before you execute your command, then close immediately. Try this: Private Sub AddSubmitB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddSubmitB.Click Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Jasmine\db.mdb" Dim con As OleDb.OleDbConnection con = New OleDb.OleDbConnection(strcon) Dim cmd As New OleDb.OleDbCommand cmd.Connection = con Dim strsql As String strsql = "Insert into member (BorrowerId, password, MemberType, Fname, Lname, Gender, Address1, Address2, Address3, ContactNo, HandPhNo, Email, CourseOfStudy, EnrolledDate, ExpiryDate) values ('" & StudIdTB.Text & "','" & StudPwTB.Text & "','" & UgTB.Text & "','" & StudFnTB.Text & "','" & StudLnTB.Text & "','" & StudGenderCLB.Text & "','" & StudAdd1TB.Text & "','" & StudAdd2TB.Text & "','" & StudAdd3TB.Text & "','" & StudHmTB.Text & "','" & StudHpTB.Text & "','" & StudMailTB.Text & "','" & CosCB.Text & "','" & EnrolledCB.Text & "','" & ExpiryCB.Text & "')" cmd.CommandText = strsql con.Open() cmd.ExecuteNonQuery() con.Close() MsgBox("New Member Added!") Me.Close() End Sub I haven't changed any of strsql because you seem to think the query is ok. Only you would know that. Check the single quotes etc are legal.. For queries containing this many fields, you should be using parameter queries. Once you get used to them, you will use them all the time. They are much easier to read and you can check/set data types as you go. Steve

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups