473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Variable from datareader

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

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #1
1 1102
"Jim via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
news:f8******************************@DotNetMonste r.com:
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) : )

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! When reading a value from an SQL database i get to a DateTime variable... How can i check that the there is no value assigned? Since i cant use if(myDate.ShortDate != null) ? Regards
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
10
by: Daniel Fernandes | last post by:
Hi there Let's say due to several reasons I have an ASP.Net application that has a database access class that stores a database connection in a shared member : public class dataaccess ...
2
by: Jim via DotNetMonster.com | last post by:
Hi, I'm passing a variable to another page through a querystring. I then want to use that variable to retrieve records from a database to poulate a dropdownlist. I can read the variable from the...
5
by: Jim via DotNetMonster.com | last post by:
Hi, I need to pass the value of a variable from one function to another but I don't seem to get the value. I declare the variable outside all functions. What I'm trying to do is that when the...
4
by: Jim via DotNetMonster.com | last post by:
Hi, How can I assign the result of a function to a variable. I need to get the result so that I can query the database again. What I'm trying is:...
2
by: Shapper | last post by:
Hello, I have a DataReader which returns only one record from a database: ID Name Content 12 hello world Is it possible to create a variable named var_hello which value is "world"?
10
by: Tony K | last post by:
How would I assign the result of a SQL query to a variable. The result of the following statement will ALWAYS result in 1 row returned. SELECT ProductDescription, ProductID FROM ...
2
by: bcshaw | last post by:
Hey all I have a vb.net/asp.net dynamic website connected to an access database using a oledb connection. I use a datareader to retrieve the results of a query and iterate through the results using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.