Data base insert Error HELP!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bonzol

    #1

    Data base insert Error HELP!

    Can someone tell me why I get this error

    "An unhandled exception of type 'System.Data.Ol eDb.OleDbExcept ion'
    occurred in system.data.dll "

    when i do this

    Private Sub btnAdd_Click(By Val sender As System.Object, ByVal e As
    System.EventArg s) Handles btnAdd.Click


    Dim strSQL As String
    Dim cmd As OleDbCommand
    strSQL = "INSERT INTO
    Engineer(Eng-name,Eng-Qual,Eng-Mobile,Eng-Phone,Eng-NOK,Spec-ID)
    VALUES([txtName.Text] ,[txtQual.Text], [txtMobile.Text],
    [txtPhone.Text], [txtNOK.text] ,[Spec-ID.Text] )"
    cmd = New OleDbCommand(st rSQL, OleDbConnection 1)
    OleDbConnection 1.Open()
    cmd.ExecuteNonQ uery()



    End Sub

    Thanx

  • Cor Ligthert [MVP]

    #2
    Re: Data base insert Error HELP!

    Bonzol,

    Are you sure that there is a primary key in those updates.

    (The same as with your first question which should work as well)

    Cor

    "Bonzol" <Bonzol@hotmail .com> schreef in bericht
    news:1149237919 .407176.5850@i4 0g2000cwc.googl egroups.com...[color=blue]
    > Can someone tell me why I get this error
    >
    > "An unhandled exception of type 'System.Data.Ol eDb.OleDbExcept ion'
    > occurred in system.data.dll "
    >
    > when i do this
    >
    > Private Sub btnAdd_Click(By Val sender As System.Object, ByVal e As
    > System.EventArg s) Handles btnAdd.Click
    >
    >
    > Dim strSQL As String
    > Dim cmd As OleDbCommand
    > strSQL = "INSERT INTO
    > Engineer(Eng-name,Eng-Qual,Eng-Mobile,Eng-Phone,Eng-NOK,Spec-ID)
    > VALUES([txtName.Text] ,[txtQual.Text], [txtMobile.Text],
    > [txtPhone.Text], [txtNOK.text] ,[Spec-ID.Text] )"
    > cmd = New OleDbCommand(st rSQL, OleDbConnection 1)
    > OleDbConnection 1.Open()
    > cmd.ExecuteNonQ uery()
    >
    >
    >
    > End Sub
    >
    > Thanx
    >[/color]


    Comment

    • Bonzol

      #3
      Re: Data base insert Error HELP!

      The Primary key is an autogenerated number not to be inputed, via the
      form, does that matteR?

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Data base insert Error HELP!

        Bonzol,

        You can add this to your code and have than a look what it says.

        Try
        cmd.ExecuteNonQ uery()
        Catch ex as OleDBException
        messagebox.show (ex.Tostring)
        Cor

        I am curious what it says,

        Cor

        "Bonzol" <Bonzol@hotmail .com> schreef in bericht
        news:1149247043 .628118.247760@ h76g2000cwa.goo glegroups.com.. .[color=blue]
        > The Primary key is an autogenerated number not to be inputed, via the
        > form, does that matteR?
        >[/color]


        Comment

        • Bonzol

          #5
          Re: Data base insert Error HELP!

          It says

          System.Data.ole DB.OleDbExcepti on: Syntax error in INSERT INTO
          statement.
          at System.data.Ole Db.OleDbComman. ExecuteCommandT extErrorHanding (Int32
          hr)
          at System.data.Ole Db.OleDbComman. ExecuteCommandT extForSingle
          Result(tagDBPAR AMS dbParams, Object& executeResult)
          at System.data.Ole Db.OleDbComman. ExecuteCommandT ext(Object&
          executeResult)
          at System.data.Ole Db.OleDbComman. ExecuteCommand( CommandBehavior ,
          Object& executeResult)
          at System.data.Ole Db.OleDbComman. ExecuteCommandC ommandBehaviour
          behaviour, String method)
          at System.data.Ole Db.OleDbComman. ExecuteCommand. ExecuteNonQuery ()
          at.Project1.frm NewEngineer.btn Add_click(obkec t sender, EventArgs e) in
          E c:\inetpub/wwwProject1\new Engineer.vb:lin e 326

          Comment

          • Cor Ligthert [MVP]

            #6
            Re: Data base insert Error HELP!

            Bonzol,

            Doi, you did not follow the code from Ghost.....

            Have a look at that last part about the parameters in his code.

            Cor


            Comment

            • Bonzol

              #7
              Re: Data base insert Error HELP!

              yeah, I had a problem with it, and am waiting a reply in that other
              thread

              Comment

              Working...