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
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