P
phil
Hi,
With the code below, i get the error:
ExecuteReader: Connection property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: ExecuteReader:
Connection property has not been initialized.
Source Error:
Line 25: oConnection.Open()
Line 26: comd = New SqlCommand("select naam,type from pc")
Line 27: dtreader = comd.ExecuteReader
Line 28: x = 0
Line 29: If dtreader.HasRows Then
Source File: D:\Inetpub\wwwroot\aspnet\Begin\Chapter07\access2.aspx Line:
27
--------------------------------------------------------------
My code:
Dim oConnection As System.Data.OleDb.OleDbConnection
oConnection = New System.Data.OleDb.OleDbConnection()
Dim comd As SqlCommand
Dim dtreader As SqlDataReader
Dim x As Integer
Dim sConnectionString As String
sConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source
= d:\access\nemi.mdb"
oConnection.ConnectionString = sConnectionString
oConnection.Open()
comd = New SqlCommand("select name,type from pc")
dtreader = comd.ExecuteReader
x = 0
If dtreader.HasRows Then
While dtreader.Read
x = x + 1
Response.Write(dtreader.Item("naam"))
Response.Write("<br>")
End While
End If
Response.Write(x)
dtreader.Close()
oConnection.Close()
Thanks
Phil
With the code below, i get the error:
ExecuteReader: Connection property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: ExecuteReader:
Connection property has not been initialized.
Source Error:
Line 25: oConnection.Open()
Line 26: comd = New SqlCommand("select naam,type from pc")
Line 27: dtreader = comd.ExecuteReader
Line 28: x = 0
Line 29: If dtreader.HasRows Then
Source File: D:\Inetpub\wwwroot\aspnet\Begin\Chapter07\access2.aspx Line:
27
--------------------------------------------------------------
My code:
Dim oConnection As System.Data.OleDb.OleDbConnection
oConnection = New System.Data.OleDb.OleDbConnection()
Dim comd As SqlCommand
Dim dtreader As SqlDataReader
Dim x As Integer
Dim sConnectionString As String
sConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source
= d:\access\nemi.mdb"
oConnection.ConnectionString = sConnectionString
oConnection.Open()
comd = New SqlCommand("select name,type from pc")
dtreader = comd.ExecuteReader
x = 0
If dtreader.HasRows Then
While dtreader.Read
x = x + 1
Response.Write(dtreader.Item("naam"))
Response.Write("<br>")
End While
End If
Response.Write(x)
dtreader.Close()
oConnection.Close()
Thanks
Phil