D
Damian
Hi everyone !
I am having a problem getting the datareader to work. It seems that it
doesnt get instantiated when i Dim it. The locals window when i run
the program has myReader ( the sqldatareader) set to Nothing and it
doesnt change. I tried adding the New keyword but it doesnt Build the
app , it comes up with an error saying it is not accessible in this
context because it is "Private".
Here is the code:
Dim err As Exception
Dim sConnString As String
Dim sql As String
Dim nwindConn As New SqlClient.SqlConnection
Dim authorsCMD As New SqlClient.SqlCommand
Dim myReader As SqlClient.SqlDataReader
sConnString = "Data
Source=sydsql;uid=DBDeveloper;pwd=password;Initial Catalog=northwind;"
sql = "Select au_fname,au_lname from Authors"
Try
nwindConn.ConnectionString = sConnString
nwindConn.Open()
authorsCMD.Connection = nwindConn
authorsCMD.CommandText = sql
myReader = authorsCMD.ExecuteReader() <--- crashes on
this line
If myReader.HasRows Then
Do While myReader.Read()
cboAuthors.Items.Add(myReader.GetString(0))
Loop
End If
Catch
MsgBox("Error occurred: " & err.ToString)
End Try
I am able to connect to the database.The code crashes on the following
line:
myReader = authorsCMD.ExecuteReader(). Says MyReader is set to
nothing.
Any ideas ?
Any help would be appreciated !
I am having a problem getting the datareader to work. It seems that it
doesnt get instantiated when i Dim it. The locals window when i run
the program has myReader ( the sqldatareader) set to Nothing and it
doesnt change. I tried adding the New keyword but it doesnt Build the
app , it comes up with an error saying it is not accessible in this
context because it is "Private".
Here is the code:
Dim err As Exception
Dim sConnString As String
Dim sql As String
Dim nwindConn As New SqlClient.SqlConnection
Dim authorsCMD As New SqlClient.SqlCommand
Dim myReader As SqlClient.SqlDataReader
sConnString = "Data
Source=sydsql;uid=DBDeveloper;pwd=password;Initial Catalog=northwind;"
sql = "Select au_fname,au_lname from Authors"
Try
nwindConn.ConnectionString = sConnString
nwindConn.Open()
authorsCMD.Connection = nwindConn
authorsCMD.CommandText = sql
myReader = authorsCMD.ExecuteReader() <--- crashes on
this line
If myReader.HasRows Then
Do While myReader.Read()
cboAuthors.Items.Add(myReader.GetString(0))
Loop
End If
Catch
MsgBox("Error occurred: " & err.ToString)
End Try
I am able to connect to the database.The code crashes on the following
line:
myReader = authorsCMD.ExecuteReader(). Says MyReader is set to
nothing.
Any ideas ?
Any help would be appreciated !