beginner connection error

Wirloff

Member
Joined
Mar 2, 2005
Messages
19
Location
Belgium
Programming Experience
1-3
Hi, in the next couple of weeks I have to developpe a vb.net application witch uses MS Access a lot. I have been able to fill up comboboxes with data from database. But I just don't manage to place some silly names into the database with the insert command and executeNonQuery.. I know it must a little detail but I just don't find it...
Always shows "System.exception"......

Example:
Private
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= C:\myDatabase.mdb;"

Dim oConn As OleDbConnection = New OleDbConnection(connectionString)

Dim strSQL As String = "insert into client values wirloff"

Dim oCmd As OleDbCommand = New OleDbCommand(strSQL, oConn)

Try

oConn.Open()

oCmd.ExecuteNonQuery()

Catch ex As Exception

Throw New Exception("Failure", ex)

End Try

End Sub

 
Your insert command is wrong. String values need ' around them ( eg 'wirloff'). Also I'd strongly recoment putting the column names in, like this:
"insert into client (MyCol1, MyCol2.....) values ('wirloff', 'wirloff2'...... "

You should also close the connection after you executenonquery.

TPM
 
Back
Top