help badly needed.......newbie

bzeus

Member
Joined
Feb 22, 2005
Messages
14
Programming Experience
Beginner
I'm trying to connect to an access database using this coding:

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim str AsString
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\eoaoffice\eoa.mdb;")

cn.Open()
str = "insert into customer(cus_namess) values('" & names.Text & "')"
cmd = New OleDbCommand(Str, cn)
cmd.ExecuteScalar()
cn.Close()

When the code is ran this error shows:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll for the line that shows cmd.ExecuteScalar()...

please help me....thank you so much....

 
bzeus said:
i'm getting the same error for the same line.....

this is how i did mine:
Imports System.IO
PublicClass Form1
inherits System.Windows.Forms.Form
im CN AsNew ADODB.Connection()
Dim RS AsNew ADODB.Recordset()
Region " Windows Form Designer generated code "

PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
CN =
New ADODB.Connection()
CN.Provider = "MICROSOFT.JET.OLEDB.4.0" 'ACCESS CONNECTION
CN.Open("a:\ something\mortgage.MDB")
RS =
New ADODB.Recordset()
RS.Open("select *from client order by Name", CN, 1, 2)

 
I wouldn't suggest using the ADODB as shelly121 has shown as the is the older way of doing it.
The way you have shown (using the new ADO.NET) should have worked as I don't see any mistakes.
You could place Try/Catch blocks to catch and display the error message.

How did you solve the problem?
 
i created the same database structure in sql server and use a sql server connection it worked....but i still don't know what was wrong with the previous coding done with access database.......:)
 
your original code... only had one error. You want to open a command not a database connection... leave the DbConnection closed until you execute the query

If you were to change the line cn.open to cmd.connection.open your code would be fine.
 
Back
Top