Data base insert Error HELP!

  • Thread starter Thread starter Bonzol
  • Start date Start date
B

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
 
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
 
The Primary key is an autogenerated number not to be inputed, via the
form, does that matteR?
 
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
 
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
 
Bonzol,

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

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

Cor
 
Back
Top