473,387 Members | 3,033 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,387 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 3064
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.