myConnection.Open() Error

S

SOlva

This is the code that I am running can anyone help me
understand why I get the following error

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




' IMport Data and Oledb namespaces
Imports System.Data
Imports System.Data.OleDb

Public Class Form1
Inherits System.Windows.Forms.Form
Dim myConnection As OleDbConnection = New _
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
database = c:\concord.mdb")
Dim myDataAdapter As New OleDbDataAdapter()
Dim myDataSet As DataSet = New DataSet()
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
' Set the SelectCommand properties
myDataAdapter.SelectCommand = New OleDbCommand()
myDataAdapter.SelectCommand.Connection =
myConnection
myDataAdapter.SelectCommand.CommandText = _
"SELECT CustNum, WorkPhone, Alt Phone,
Firstname, LastName, Address, Address1, City,
StateOrProvince " & _
"FROM customer " & _
"ORDER BY LastName, LastName"
myDataAdapter.SelectCommand.CommandType =
CommandType.Text

' OPen the database connection
myConnection.Open()
'Now execute the command
myDataAdapter.SelectCommand.ExecuteNonQuery()
' Fill DataSet object with data
myDataAdapter.Fill(myDataSet, "customers")

'Close the database connection
myConnection.Close()
' Set the dataGrid properties to bind it to our
data
grdCustomerInfo.DataSource = myDataSet
grdCustomerInfo.DataMember = "customers"
End Sub
End Class
 
W

William Ryan

Which line is crashing? Verify that the file Exists first... If
File.Exists("C:\concord.mdb") then if it does, make sure you that you have
persmissions to the file and to the database... If you have a username and
password, make sure you include the rest of the connectionstring.
http://www.connectionstrings.com . If that doesn't fix it, put a breakpoint
next to your commandtext once it's completed and make sure you can fire it
against Access itself without ADO.NET. If you could tell me where the
exception is being raised, it'd help a lot in diagnosing it.

HTH,

Bill
 
G

Guest

it is happening a t myConnecyion.Open()
-----Original Message-----
Which line is crashing? Verify that the file Exists first... If
File.Exists("C:\concord.mdb") then if it does, make sure you that you have
persmissions to the file and to the database... If you have a username and
password, make sure you include the rest of the connectionstring.
http://www.connectionstrings.com . If that doesn't fix it, put a breakpoint
next to your commandtext once it's completed and make sure you can fire it
against Access itself without ADO.NET. If you could tell me where the
exception is being raised, it'd help a lot in diagnosing it.

HTH,

Bill




.
 
G

Guest

I got passed that error now it is saying the same thing at
the myDataAdapter.SelectCommand.ExecuteNonQuery(). Any
ideas I also sent you an email.
 
C

Cor

Hi Anonymous,

Why are you using that
the myDataAdapter.SelectCommand.ExecuteNonQuery().

I do not understand why you need it

Why not try what happens when you set a ' before it

I hope this helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top