insert into table error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • davincinewfie
    New Member
    • Dec 2007
    • 6

    insert into table error

    oledbexception was unhandled....sy ntax error in insert into statement is the error I get I can edit/update information, delete and everything except for add

    the cmdSave code is::::

    Dim drNewRow As DataRow = m_dtTable1.NewR ow()

    With Me
    drNewRow("id") = .txtid.Text
    drNewRow("Date" ) = .txtdate.Text
    drNewRow("Time" ) = .txttime.Text
    drNewRow("CallS ign") = .txtcallsign.Te xt
    drNewRow("Freq" ) = .txtfreq.Text
    drNewRow("Mode" ) = .txtmode.Text
    drNewRow("RST") = .txtrst.Text
    drNewRow("Notes ") = .txtnotes.Text
    drNewRow("QslTX ") = .txtqsltx.Text
    drNewRow("QslRX ") = .txtqslrx.Text
    End With

    m_dtTable1.Rows .Add(drNewRow)
    m_daTable1.Upda te(m_dtTable1) <<<<-----ERROR HERE

    m_intRowPositio n = m_dtTable1.Rows .Count - 1

    m_blnNewRecord = False
    m_blnUpdateReco rd = False

    ShowCurrentReco rd()


    ----------------------------------------------------------------

    declarations:::
    Public m_cnTable1 As New OleDb.OleDbConn ection
    Public m_daTable1 As OleDb.OleDbData Adapter
    Public m_cbTable1 As OleDb.OleDbComm andBuilder
    Public m_dtTable1 As New DataTable
    Public m_intRowPositio n As Integer = 0
    Public m_blnNewRecord As Boolean = False
    Public m_blnUpdateReco rd As Boolean = False


    ----------------------------------------------------------------

    I can post full code if need be but I figured going through that much might be enough
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by davincinewfie
    oledbexception was unhandled....sy ntax error in insert into statement is the error I get I can edit/update information, delete and everything except for add

    the cmdSave code is::::

    [CODE=VB]

    Dim drNewRow As DataRow = m_dtTable1.NewR ow()

    With Me
    drNewRow("id") = .txtid.Text
    drNewRow("Date" ) = .txtdate.Text
    drNewRow("Time" ) = .txttime.Text
    drNewRow("CallS ign") = .txtcallsign.Te xt
    drNewRow("Freq" ) = .txtfreq.Text
    drNewRow("Mode" ) = .txtmode.Text
    drNewRow("RST") = .txtrst.Text
    drNewRow("Notes ") = .txtnotes.Text
    drNewRow("QslTX ") = .txtqsltx.Text
    drNewRow("QslRX ") = .txtqslrx.Text
    End With

    m_dtTable1.Rows .Add(drNewRow)
    m_daTable1.Upda te(m_dtTable1) <<<<-----ERROR HERE

    m_intRowPositio n = m_dtTable1.Rows .Count - 1

    m_blnNewRecord = False
    m_blnUpdateReco rd = False

    ShowCurrentReco rd()


    ----------------------------------------------------------------

    declarations:::
    Public m_cnTable1 As New OleDb.OleDbConn ection
    Public m_daTable1 As OleDb.OleDbData Adapter
    Public m_cbTable1 As OleDb.OleDbComm andBuilder
    Public m_dtTable1 As New DataTable
    Public m_intRowPositio n As Integer = 0
    Public m_blnNewRecord As Boolean = False
    Public m_blnUpdateReco rd As Boolean = False
    [/CODE]

    ----------------------------------------------------------------

    I can post full code if need be but I figured going through that much might be enough
    Greetings!

    I have not yet handled insert/update commands in his fashion, but one thing I see is should you also dimension daTable1 as you did here:

    [CODE=VB]

    Dim drNewRow As DataRow = m_dtTable1.NewR ow()

    [/CODE]

    Also, are you updating to the daTable1 table?

    Should you say:

    [CODE=VB]

    m_daTable1.Rows .Update(m_dtTab le1)

    [/CODE]

    If nothing is working you might consider adding a different code to add. Something I am actually working on, works great. disregard if your works for you:

    [CODE=VB]

    Dim my_database As Database
    Dim my_record As Recordset
    Set my_database = OpenDatabase("C :\DataGram\Data _Central.mdb")
    Set my_record = my_database.Ope nRecordset("sel ect * from Employee where Your_Price='" & Text1(0).Text & "'")
    my_record.Edit
    my_record!Your_ Price = Text1(0).Text
    my_record!Name = Text1(1).Text
    my_record!Crime _Rate_1 = Text1(2).Text
    my_record!Crime _Rate_2 = Text1(3).Text
    my_record!Type = Text1(4).Text

    my_record.Updat e
    my_record.Close
    my_database.Clo se

    End If

    End Sub
    [/CODE]

    Still try adding Rows.Update to the line mentioned, okay.

    In a bit!

    Dököll

    Comment

    • Dököll
      Recognized Expert Top Contributor
      • Nov 2006
      • 2379

      #3
      Nevermind, I think you're refering to Insert, you must Add Insert, not Update, so perhaps Rows.Insert, or simply Insert, instead of Update, my apologies. I thought you were having issues updating when I read that portion of the code.

      See if that works:-)

      Comment

      • davincinewfie
        New Member
        • Dec 2007
        • 6

        #4
        I replaced m_dtTable1.Rows .Add(drNewRow) with m_dtTable1.Rows .InsertAt(drNew Row, m_dtTable1.Rows .Count + 1)

        still same error


        m_daTable1.Inse rtCommand is the only insert available to me and that doesnt seem to be the right way to go either...thisis sooo frustrating, so close to finishing but yet soo far

        Comment

        • Torgg
          New Member
          • Dec 2007
          • 41

          #5
          I think you are using reserved words as field names in the database (i.e. "Date" and "Time") try puting square brackets around those two words in your code, like so "[Date]" "[Time]" or you can change the field names (in the database) to somthing like "EventDate" and "EventTime" . When using reserved words as field names in a database you have to use square brackets when using those field names in your query/code. There is a long list reserved words, here is a link to a list.



          Notes: you are also using "Notes" which is not a reserved word but "Note" is also "ID" is not on the list but I imagin it could give you problems. I would recomend (if possable) to change those field names as well. I hope this helps!


          Torgg

          Comment

          • davincinewfie
            New Member
            • Dec 2007
            • 6

            #6
            changed date to ddate same thing will work on the other fields and see how it goes

            Comment

            • davincinewfie
              New Member
              • Dec 2007
              • 6

              #7
              WOOOHOOO

              changed id date time and notes left all other fields the same and bingo worked best kind

              leave it to me to pick names that are reserved

              thank you soooooooooOOOOO OOOOOOOOOoooooo ooooooo much, this has been a 2 week battle

              thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou

              Comment

              • Torgg
                New Member
                • Dec 2007
                • 41

                #8
                I'm so glad I could help... take care!

                Comment

                Working...