Variable from datareader

  • Thread starter Jim via DotNetMonster.com
  • Start date
J

Jim via DotNetMonster.com

Hi,

I'm trying to set one of the columns in the datareader to a variable so
that I can use it in a different function. When I do that then all the
other values in the data reader don't show up.

So I'm doing this:
If (dataReader.Read = True) Then
LessonID=dataReader("LessonID")
End If

Then only the LessonID shows up and nothing else. How can I set the
variable so that I can get that column and all the others in the data
reader?

This is the full function code:

Function GetPage(ByVal courseNumber As Integer, ByVal lessonNumber As
Integer, ByVal PageNumber As Integer) As System.Data.IDataReader

Dim strConnection As String
strConnection = ConfigurationSettings.AppSettings
("ConnectionString")

Dim dbConnection As New SqlConnection(strConnection)

Dim queryString As String = "SELECT [tblPage].*, [tblLesson]
..[LessonNumber],[tblLesson].[LessonTitle], [tblCourse].[CourseNumber],
[tblCourse].[CourseTitle] FROM [tblPage], [tblLesson], [tblCourse] WHERE ((
[tblPage].[Pa"& _
"geNumber] = @PageNumber) AND ([tblLesson].[LessonNumber] =
@LessonNumber) AND (["& _
"tblCourse].[CourseNumber] = @CourseNumber)) AND tblPage.lessonID
= tblLesson.lessonID AND tblLesson.CourseID = tblCourse.CourseID"

Dim dbCommand As New SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_pageNumber As New SqlParameter
dbParam_pageNumber.ParameterName = "@pageNumber"
dbParam_pageNumber.Value = lessonNumber
dbParam_pageNumber.DbType = DbType.Int32
dbCommand.Parameters.Add(dbParam_pageNumber)
Dim dbParam_lessonNumber As New SqlParameter
dbParam_lessonNumber.ParameterName = "@LessonNumber"
dbParam_lessonNumber.Value = lessonNumber
dbParam_lessonNumber.DbType = DbType.Int32
dbCommand.Parameters.Add(dbParam_lessonNumber)
Dim dbParam_courseNumber As New SqlParameter
dbParam_courseNumber.ParameterName = "@CourseNumber"
dbParam_courseNumber.Value = courseNumber
dbParam_courseNumber.DbType = DbType.Int32
dbCommand.Parameters.Add(dbParam_courseNumber)

dbConnection.Open
Dim dataReader As IDataReader = dbCommand.ExecuteReader
(CommandBehavior.CloseConnection)

If (dataReader.Read = True) Then
LessonID=dataReader("LessonID")
End If

Return dataReader

End Function

Thanks
 
L

Lucas Tam

I'm trying to set one of the columns in the datareader to a variable so
that I can use it in a different function. When I do that then all the
other values in the data reader don't show up.

DataReader <- Reader (Read Only) : )
 

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