The Student Room Group

MS Access 2003 integration with VB.NET help

Hey

I am having problems inserting data into an access database (2003)

Here is my code that is under a button press:

Try
OleDBConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Computer Repairs.mdb;")
OleDBConnection.Open()
OleDBCommand = New System.Data.OleDb.OleDbCommand("INSERT INTO Client (ID, Name, Contact Name, Address, Post Code, Phone Number, Email) VALUES (2, 'James', 'Brook', 'Address', 'Post Code', '01234567890', '[email protected]')", OleDBConnection)
OleDBCommand.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
OleDBConnection.Close()
End Sub

Here is the design view of the Client table in Access (Also attachted as a picture):

Field Name - Data Type
ID - Number (Primary Key)
Name - Text
Client Name - Text
Address - Text
Post Code - Text
Phone Number - Text
Email - Text

When I try and run the code I get the following error:

"System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at Computer_Repairs.Form1.Button4_Click(Object sender, EventArgs e) in U:\Files\Visual Studio 2005\Projects\Computer Repairs\Form1.vb:line 128"


Any Ideas?

Latest

Trending

Trending