G
Guest
Hi
VB.NET 2005 Express edition
Microsoft Access 2000 (SP-3)
Having trouble writing an "insert into" command for a Microsoft table I'm
accessing through oledb.
I've tried to follow the same principle I'd use if it was an sql database
but I'm getting an error telling me the syntax of the "insert into" command
is incorrect.
Can anyone tell looking at my code what I'm doing wrong or suggest the
correct syntax.
Here is the code I'm using
Imports System.Data.OleDb
Imports System.Data
Public Class myForm
Dim myConnection As OleDbConnection
Dim myCommand As OleDb.OleDbCommand
Dim insertCMD, deleteCMD, updateCMD, insertCMDLogIn, insertCMDLogOut,
selectCMD As String
Private Sub insertRecord()
myConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source='C:\myDbase.mdb'")
insertCMD = "INSERT INTO myTable (field1, field2, field3) VALUES
(@fone, @ftwo, @fthree);"
myCommand = New OleDbCommand(insertCMD, myConnection)
myCommand.Parameters.Add(New OleDbParameter("@fone",
OleDbType.Integer))
myCommand.Parameters.Add(New OleDbParameter("@ftwo",
OleDbType.VarChar))
myCommand.Parameters.Add(New OleDbParameter("@fthree",
OleDbType.Date)) '? not sure if this is the correct object type
myCommand.Parameters(0).Value = Me.fonelabel.Text
myCommand.Parameters(1).Value = Me.ftwolabel.Text
myCommand.Parameters(2).Value = Now() 'must insert both date and
time, not just date
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub
End class
Any help appreciated
Thanks
Michael Bond
VB.NET 2005 Express edition
Microsoft Access 2000 (SP-3)
Having trouble writing an "insert into" command for a Microsoft table I'm
accessing through oledb.
I've tried to follow the same principle I'd use if it was an sql database
but I'm getting an error telling me the syntax of the "insert into" command
is incorrect.
Can anyone tell looking at my code what I'm doing wrong or suggest the
correct syntax.
Here is the code I'm using
Imports System.Data.OleDb
Imports System.Data
Public Class myForm
Dim myConnection As OleDbConnection
Dim myCommand As OleDb.OleDbCommand
Dim insertCMD, deleteCMD, updateCMD, insertCMDLogIn, insertCMDLogOut,
selectCMD As String
Private Sub insertRecord()
myConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source='C:\myDbase.mdb'")
insertCMD = "INSERT INTO myTable (field1, field2, field3) VALUES
(@fone, @ftwo, @fthree);"
myCommand = New OleDbCommand(insertCMD, myConnection)
myCommand.Parameters.Add(New OleDbParameter("@fone",
OleDbType.Integer))
myCommand.Parameters.Add(New OleDbParameter("@ftwo",
OleDbType.VarChar))
myCommand.Parameters.Add(New OleDbParameter("@fthree",
OleDbType.Date)) '? not sure if this is the correct object type
myCommand.Parameters(0).Value = Me.fonelabel.Text
myCommand.Parameters(1).Value = Me.ftwolabel.Text
myCommand.Parameters(2).Value = Now() 'must insert both date and
time, not just date
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub
End class
Any help appreciated
Thanks
Michael Bond