Using executeNonQuery to execute an INSERT stmt [RESOLVED]
I am attempting to use the executeNonQuery method of a
command object to execute an insert SQL statement on a table in
an Access database. I have successfully used executeNonQuery
to perform an Update to a table but I can't seem to get this one
to work. Here is my code, I have printed the generated query
and tested it in access and the query works fine, must be
something with my VB code. I'm new to .NET so I'm not seeing
the problem. Any help is appreciated. Here is my code.
VB Code:
Private Sub Insert_Row()
Dim strSQL As String
Dim strconn As String
Dim connection As New OleDb.OleDbConnection
Dim a() As String = cmbExpenseAccount.SelectedItem.Split()
strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = S:\20YRLongRangePlan\CapitalLogistics.mdb"
strSQL = "INSERT INTO tblProjects VALUES(" & projectID
& ", '', '', '" & a(0) & "', " & Chr(34) & txtDescription.Text & Chr(34)
& ", " & Chr(34) & txtManufacturer.Text & Chr(34) & ", '', '', " & Chr
(34) & txtProjectLife.Text & Chr(34) & ", " & Chr(34) &
cmbReviewYear.SelectedItem & Chr(34) & ", " & Chr(34) &
cmbReplacementYear.SelectedItem & Chr(34) & ", " & Chr(34) &
txtArchitectComments.Text & Chr(34) & ", " & Chr(34) &
cmbArchitect.SelectedItem & Chr(34) & ", '', '', '', '', " & Chr(34) &
cmbGrant.SelectedItem & Chr(34) & ", '', '', '', '', '', '', '', '', " &
Me.projDesc & ");"
connection.ConnectionString = strconn
connection.Open()
Dim command As New OleDb.OleDbCommand
command.CommandText = strSQL
command.Connection = connection
command.ExecuteNonQuery()
MsgBox("Project Information Inserted Successfully.", MsgBoxStyle.Information)
End Sub
With an error occuring on the command.ExecuteNonQuery() line.
Thanks in advance for any help. :)