I am trying to find the proper syntax for my INSERT INTO statement. I am trying to take three variables (part,order,cust) and add them to a table (tblHistory) in the fields (partno,orderno,cust). This is what my code looks like so far...
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Dim sConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\MSTRHIST.mdb;" & _
"User ID=Admin;" & _
"Password="
Dim oOleDbConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection(sConnString)
Dim objCommand As New OleDb.OleDbCommand()
Dim strSQL As String
strSQL = "INSERT INTO tblHistory (catno, wo, cust_name) VALUES (part, work, cust)"
oOleDbConnection.Open()
With objCommand
.Connection = objDBConnection
.CommandText = strSQL
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
objDBConnection.Close()
oOleDbConnection = Nothing
objCommand = Nothing
End Sub
I know the code opens the database, but after that, it doesnt do add anything. Any suggestion would be greatly appreciated. Thanks
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Dim sConnString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\MSTRHIST.mdb;" & _
"User ID=Admin;" & _
"Password="
Dim oOleDbConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection(sConnString)
Dim objCommand As New OleDb.OleDbCommand()
Dim strSQL As String
strSQL = "INSERT INTO tblHistory (catno, wo, cust_name) VALUES (part, work, cust)"
oOleDbConnection.Open()
With objCommand
.Connection = objDBConnection
.CommandText = strSQL
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
objDBConnection.Close()
oOleDbConnection = Nothing
objCommand = Nothing
End Sub
I know the code opens the database, but after that, it doesnt do add anything. Any suggestion would be greatly appreciated. Thanks