By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 904 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

myConnection.Open() Error

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

"SOlva" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
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

Nov 20 '05 #2

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

Bill

"SOlva" <an*******@discussions.microsoft.com> wrote in messagenews:07****************************@phx.gbl...
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

.

Nov 20 '05 #3

P: n/a
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.
-----Original Message-----
Which line is crashing? Verify that the file Exists first... IfFile.Exists("C:\concord.mdb") then if it does, make sure you that you havepersmissions to the file and to the database... If you have a username andpassword, make sure you include the rest of the connectionstring.http://www.connectionstrings.com . If that doesn't fix it, put a breakpointnext to your commandtext once it's completed and make sure you can fire itagainst Access itself without ADO.NET. If you could tell me where theexception is being raised, it'd help a lot in diagnosing it.
HTH,

Bill

"SOlva" <an*******@discussions.microsoft.com> wrote in messagenews:07****************************@phx.gbl...
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

.

Nov 20 '05 #4

P: n/a
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
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.