INSERT into access database using vb.net/ado.net..problem 
Author Message
 INSERT into access database using vb.net/ado.net..problem

Hello,

I am unable to insert into the access database. I have a
windows form application under vb.net and am using
ado.net to try to INSERT new entries into my database.
However, I keep getting errors. I would appreciate if
someone could help me out here.

Code snippet below.

Dim conn As New OleDbConnection()
conn.ConnectionString = connect

Dim insertStr As String = "INSERT INTO finaldb
course,lname,fname,ssn,emailid VALUES infoArray
(4),infoArray(0),infoArray(1),infoArray(2),infoArray(3)"

Dim cmd As OleDbCommand = New OleDbCommand()
cmd.Connection = conn
cmd.CommandText = insertStr

conn.Open()
cmd.ExecuteNonQuery()
conn.Close()

I would appreciate any help.

cheers
John



Thu, 10 Feb 2005 18:02:11 GMT  
 INSERT into access database using vb.net/ado.net..problem
what is the error messages ?

Cheers,
Maartin.

Quote:
> Hello,

> I am unable to insert into the access database. I have a
> windows form application under vb.net and am using
> ado.net to try to INSERT new entries into my database.
> However, I keep getting errors. I would appreciate if
> someone could help me out here.

> Code snippet below.

> Dim conn As New OleDbConnection()
> conn.ConnectionString = connect

> Dim insertStr As String = "INSERT INTO finaldb
> course,lname,fname,ssn,emailid VALUES infoArray
> (4),infoArray(0),infoArray(1),infoArray(2),infoArray(3)"

> Dim cmd As OleDbCommand = New OleDbCommand()
> cmd.Connection = conn
> cmd.CommandText = insertStr

> conn.Open()
> cmd.ExecuteNonQuery()
> conn.Close()

> I would appreciate any help.

> cheers
> John



Fri, 11 Feb 2005 00:58:10 GMT  
 INSERT into access database using vb.net/ado.net..problem


Fri, 19 Jun 1992 00:00:00 GMT  
 INSERT into access database using vb.net/ado.net..problem
the error message is this

An unhandled exception of
type 'System.Data.OleDb.OleDbException' occurred in
system.data.dll

cheers
John

Quote:
>-----Original Message-----
>Message unavailable



Fri, 11 Feb 2005 03:02:32 GMT  
 INSERT into access database using vb.net/ado.net..problem


Fri, 19 Jun 1992 00:00:00 GMT  
 INSERT into access database using vb.net/ado.net..problem
here is the error message

An unhandled exception of
type 'System.Data.OleDb.OleDbException' occurred in
system.data.dll

cheers
John

Quote:
>-----Original Message-----
>Message unavailable



Fri, 11 Feb 2005 03:16:33 GMT  
 INSERT into access database using vb.net/ado.net..problem
Just a guess, but Access may be funny about the syntax and want a semicolon
at the end of the "INSERT" string.
Giacomo

Quote:
> 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



Fri, 11 Feb 2005 03:35:07 GMT  
 INSERT into access database using vb.net/ado.net..problem
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

Quote:
>-----Original Message-----
>Just a guess, but Access may be funny about the syntax

and want a semicolon
Quote:
>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

>.



Fri, 11 Feb 2005 06:38:22 GMT  
 INSERT into access database using vb.net/ado.net..problem

here is the error message

An unhandled exception of
type 'System.Data.OleDb.OleDbException' occurred in
system.data.dll

There is usually some additional more specific information than what you posted. Could you check
again and post if there is any additional error info?


Microsoft MVP (Visual Basic)



Sat, 12 Feb 2005 02:39:21 GMT  
 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

> >.



Sat, 12 Feb 2005 03:27:25 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. I can not INSERT into Access95 using ADO.net and VB.NET

2. ADO.NET with ASP.NET using VB.NET

3. Using VB.Net, ADO.Net and Access

4. what create table using ADO.NET to VB.NET

5. Fatal Error, using VB .NET + ADO .NET

6. adding a record to access database using ado.net

7. Insert using ADO.NET

8. insert into using ado.net

9. Using VB.NET to open an Access database...

10. using vb to access a database on the net

11. Adding a row to Access database using VB.Net

12. Accessing vb.net class from non.vb.net apps

 

 
Powered by phpBB® Forum Software