473,395 Members | 2,468 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,395 software developers and data experts.

datareader columns

Can you define a value from a datareader through column
idexes. For example:

dim myreader as sqldatareader
SQL = select fname, lname, address from personal.

//Datareader is initialized with the above SQL code

Instead of using the following to assign values from the
reader:

while myreader.read
txtTest1.text = myreader("fname")
txtTest2.text = myreader("lname")
txtTest3.text = myreader("address")
end while
txtTest1.text = myreader.index[0]
txtTest2.text = myreaderindex[1]
txtTest3.text = myreaderindex[2]

I am looking to programatically go through the reader and
programatically assign to text boxes.

Thanks



Nov 18 '05 #1
3 3066
Hi,

yes you can. You can also get column index with column name if you use
GetOrdinal method (e.g idea is to get once the indexes with column names &
GetOrdinal and then later just use indexes).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"brian shannon" <bs******@lbrspec.com> wrote in message
news:21****************************@phx.gbl...
Can you define a value from a datareader through column
idexes. For example:

dim myreader as sqldatareader
SQL = select fname, lname, address from personal.

//Datareader is initialized with the above SQL code

Instead of using the following to assign values from the
reader:

while myreader.read
txtTest1.text = myreader("fname")
txtTest2.text = myreader("lname")
txtTest3.text = myreader("address")
end while
txtTest1.text = myreader.index[0]
txtTest2.text = myreaderindex[1]
txtTest3.text = myreaderindex[2]

I am looking to programatically go through the reader and
programatically assign to text boxes.

Thanks


Nov 18 '05 #2
Thanks for the reply- if you have time could you show me an example of
the get ordinal method.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
Public Sub ReadMyData(myConnString As String)
Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders"
Dim myConnection As New SqlConnection(myConnString)
Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader()
Dim custIdCol As Integer = myReader.GetOrdinal("CustomerID")
Do While myReader.Read()
Console.WriteLine("CustomerID = {0}", myReader.GetString(custIdCol))
Loop
myReader.Close()
myConnection.Close()
End Sub
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"brian shannon" <bs******@lbrspec.com> wrote in message
news:u$**************@TK2MSFTNGP10.phx.gbl...
Thanks for the reply- if you have time could you show me an example of
the get ordinal method.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #4

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

Similar topics

6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
7
by: Bart Schelkens | last post by:
Hi, I have 2 more questions : 1. Can I fill a datagrid by using a DataReader or does it have to be a DataSet or a DataView? 2. In my datagrid I need to display two images and one of does...
3
by: Rykie | last post by:
I have an application that constantly needs to read and write data to a SQL box. For most of my read transactions I use a datareader. I compiled a class that has all my datareader commands in it...
5
by: robecflo | last post by:
Hi Forum, i have a problem, hope somebody can give me ideas. I'm developing with windows forms and vb.net, and oracle as a database. At this moment i have a table called amortizaciones, this table...
3
by: RSH | last post by:
Hi, I have a situation where I have two datareaders, and I want to make sure any given field from Datareader A exists in Datareader B before I can do anything with that column. I tried the code...
3
by: Alex Maghen | last post by:
Hi. I have a whole bunch of queries that I'll be running and returning in OleDbDataReader objects. Some of these DataReaders will just be a simple singe table result and others will be more complex...
3
by: Martin Panggabean | last post by:
Hello All, I've kind a logic problem ... I want to fill the listView control in VB.NET with data in my mySql table using Datareader object component. But It seems that the way of how listView...
1
by: Cerebrus | last post by:
Hi all, Using : .NET 1.1, SQL Server 2000, Win 2K. Could anyone confirm if there is a bug in the SqlDataReader.GetChars() method when using CommandBehavior.SequentialAccess to get a BLOB...
2
by: =?Utf-8?B?ZGJhMTIz?= | last post by:
Note, I'm using C# I am wondering what type of control I should use for iterating through the set of records returned by callin this method below, so that I can then do some stuff with each...
3
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I'm trying to add a datagridview control to a Windows Form to display read-only information in visual basic 2005. My understanding is that datareader will be faster for this purpose. I have the...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.