
INSERT into access database using vb.net/ado.net..problem
You need to surround your values in quotes:
dim sql1 as String = "INSERT INTO finaldb ( course,
lname, fname, ssn, emailid ) VALUES ('four', 'zero', 'one',
'two', 'three');"
So your original insert should be something like:
Dim insertStr As String = "INSERT INTO finaldb
course,lname,fname,ssn,emailid VALUES('" & infoArray(4) & "','" &
infoArray(0) & "','" & infoArray(1) & "','" & infoArray(2) & "','" &
infoArray(3) & "')"
Those deleimters are " ' , ' "
You want the string resolved with single quotes around your variables
(assuming they are strings).
Joe Maki
Quote:
> I tried the semicolon at end of string.
> dim sql1 as String = "INSERT INTO finaldb ( course,
> lname, fname, ssn, emailid ) VALUES (four, zero, one,
> two, three);"
> and it still doesn't work. I run this query in the SQL
> view of access and it works fine. Is there something else
> I am missing.
> My problem stems from obtaining strings dynamically and
> then storing them into an array and then trying to insert
> the array i.e. somearray(0), somearray(1) adn etc into
> the database via an insert statement.
> Do you know of a way to insert variables/arrays into
> access database? This is my problem. The code works fine
> when I use string literals but will not work when I use
> variables.
> any suggestions.
> best regards,
> John
> >-----Original Message-----
> >Just a guess, but Access may be funny about the syntax
> and want a semicolon
> >at the end of the "INSERT" string.
> >Giacomo
> >> here is the error message
> >> An unhandled exception of
> >> type 'System.Data.OleDb.OleDbException' occurred in
> >> system.data.dll
> >> cheers
> >> John
> >> >-----Original Message-----
> >> >Message unavailable
> >.