Home All Groups Group Topic Archive Search About

Data base insert Error HELP!

Author
2 Jun 2006 8:45 AM
Bonzol
Can someone tell me why I get this error

"An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll"

when i do this

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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(strSQL, OleDbConnection1)
        OleDbConnection1.Open()
        cmd.ExecuteNonQuery()



    End Sub

Thanx

Author
2 Jun 2006 9:08 AM
Cor Ligthert [MVP]
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

Show quoteHide quote
"Bonzol" <Bon***@hotmail.com> schreef in bericht
news:1149237919.407176.5850@i40g2000cwc.googlegroups.com...
> Can someone tell me why I get this error
>
> "An unhandled exception of type 'System.Data.OleDb.OleDbException'
> occurred in system.data.dll"
>
> when i do this
>
>    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) 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(strSQL, OleDbConnection1)
>        OleDbConnection1.Open()
>        cmd.ExecuteNonQuery()
>
>
>
>    End Sub
>
> Thanx
>
Author
2 Jun 2006 11:17 AM
Bonzol
The Primary key is an autogenerated number not to be inputed, via the
form, does that matteR?
Author
2 Jun 2006 11:24 AM
Cor Ligthert [MVP]
Bonzol,

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

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

I am curious what it says,

Cor

Show quoteHide quote
"Bonzol" <Bon***@hotmail.com> schreef in bericht
news:1149247043.628118.247760@h76g2000cwa.googlegroups.com...
> The Primary key is an autogenerated number not to be inputed, via the
> form, does that matteR?
>
Author
2 Jun 2006 11:57 AM
Bonzol
It says

System.Data.oleDB.OleDbException: Syntax error in INSERT INTO
statement.
at System.data.OleDb.OleDbComman.ExecuteCommandTextErrorHanding(Int32
hr)
at System.data.OleDb.OleDbComman.ExecuteCommandTextForSingle
Result(tagDBPARAMS dbParams, Object& executeResult)
at System.data.OleDb.OleDbComman.ExecuteCommandText(Object&
executeResult)
at System.data.OleDb.OleDbComman.ExecuteCommand(CommandBehavior,
Object& executeResult)
at System.data.OleDb.OleDbComman.ExecuteCommandCommandBehaviour
behaviour, String method)
at System.data.OleDb.OleDbComman.ExecuteCommand.ExecuteNonQuery()
at.Project1.frmNewEngineer.btnAdd_click(obkect sender, EventArgs e) in
E c:\inetpub/wwwProject1\newEngineer.vb:line 326
Author
2 Jun 2006 1:04 PM
Cor Ligthert [MVP]
Bonzol,

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

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

Cor
Author
2 Jun 2006 1:36 PM
Bonzol
yeah, I had a problem with it, and am waiting a reply in that other
thread