W
William
Can someone please explain this to me. I am not understanding why this
works the way it does. The commented lines are the problems
Dim oleEmp as OleDbCommand
Dim myFinds as OleDataReader
Dim strSearch as String
Dim strFound as String
strSearch = "select * from employee where [first name]='" &
txtName.Text.ToString & "'"
oleEmp = New OleDbCommand(strSearch, oleConn)
Try
'*********************************
' Why does the next line of code not fill the datareader
'*********************************
myFinds = oleEmp.ExecuteReader
'*********************************
' in order for it to work I had to perform a read
'myFinds.Read()
'as-is the code throws up an exception
'
' No Data exists for the row/column.
'*********************************
strFound = myFinds.Item(2)
MsgBox(txtName.Text.ToString + "'s last name is " + strFound
Catch prob as Exception
MsgBox(prob.Message)
End Try
If I uncomment the myFinds.Read() line then everything works fine but I'm
just not understand why it needs to read. It seems to me that when the
myFinds = oleEmp.ExecuteReader executes the datareader should have info to
use. Like I said this is more of a curiousity than a problem.
And now for my question: Does the datareader return a count of the records
that were returned? From the above code you can see why I want to know if
there is more than one record returned.
Thanks
works the way it does. The commented lines are the problems
Dim oleEmp as OleDbCommand
Dim myFinds as OleDataReader
Dim strSearch as String
Dim strFound as String
strSearch = "select * from employee where [first name]='" &
txtName.Text.ToString & "'"
oleEmp = New OleDbCommand(strSearch, oleConn)
Try
'*********************************
' Why does the next line of code not fill the datareader
'*********************************
myFinds = oleEmp.ExecuteReader
'*********************************
' in order for it to work I had to perform a read
'myFinds.Read()
'as-is the code throws up an exception
'
' No Data exists for the row/column.
'*********************************
strFound = myFinds.Item(2)
MsgBox(txtName.Text.ToString + "'s last name is " + strFound
Catch prob as Exception
MsgBox(prob.Message)
End Try
If I uncomment the myFinds.Read() line then everything works fine but I'm
just not understand why it needs to read. It seems to me that when the
myFinds = oleEmp.ExecuteReader executes the datareader should have info to
use. Like I said this is more of a curiousity than a problem.
And now for my question: Does the datareader return a count of the records
that were returned? From the above code you can see why I want to know if
there is more than one record returned.
Thanks