473,747 Members | 3,014 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataReader

Hi I'm using a SqlDataReader to read results from a SQL
view that returns 10 columns.
Is there anyway I can reader the columns based on their
names rather than their position?

strQuery = "SELECT customerid, orderno from orders where
orderID = 1";
SqlDataReader reader = cmd.ExecuteRead er();
while(reader.Re ad())
{
myOrderNo = reader.GetInt32 (1);
}

instead of using reader.GetInt32 (1), is there any syntax
that will support reader("OrderNo ") or something like that?

Thanks for your help.

Nov 15 '05 #1
3 2684
Hi,

I do it all the time !

Did you tried it?

Just a comment, remember that you are getting the Item property in this case
that is the indexer , therefore you have to write
reader["OrderNo"] using [] instead of ()

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"lakshmi" <lm@replytonews group.net> wrote in message
news:03******** *************** *****@phx.gbl.. .
Hi I'm using a SqlDataReader to read results from a SQL
view that returns 10 columns.
Is there anyway I can reader the columns based on their
names rather than their position?

strQuery = "SELECT customerid, orderno from orders where
orderID = 1";
SqlDataReader reader = cmd.ExecuteRead er();
while(reader.Re ad())
{
myOrderNo = reader.GetInt32 (1);
}

instead of using reader.GetInt32 (1), is there any syntax
that will support reader("OrderNo ") or something like that?

Thanks for your help.

Nov 15 '05 #2
thanks a lot Ignacio. It worked.
-----Original Message-----
Hi,

I do it all the time !

Did you tried it?

Just a comment, remember that you are getting the Item property in this casethat is the indexer , therefore you have to write
reader["OrderNo"] using [] instead of ()

Hope this help,

--
Ignacio Machin,
ignacio.mach in AT dot.state.fl.us
Florida Department Of Transportation

"lakshmi" <lm@replytonews group.net> wrote in message
news:03******* *************** ******@phx.gbl. ..
Hi I'm using a SqlDataReader to read results from a SQL
view that returns 10 columns.
Is there anyway I can reader the columns based on their
names rather than their position?

strQuery = "SELECT customerid, orderno from orders where
orderID = 1";
SqlDataReader reader = cmd.ExecuteRead er();
while(reader.Re ad())
{
myOrderNo = reader.GetInt32 (1);
}

instead of using reader.GetInt32 (1), is there any syntax
that will support reader("OrderNo ") or something like that?
Thanks for your help.

.

Nov 15 '05 #3
You can use the GetOrdinal property and assign it to a string. This way you
get the performance of the Index based approach with the readability of the
Literal name. like this...

DIM fieldCityPos as integer=reader1 .getordinal("ci ty")
Using the column slows things down because the column index needs to be
resolved each time a row is read...

HTH,

Bill
"lakshmi" <lm@newsgroup.n et> wrote in message
news:89******** *************** *****@phx.gbl.. .
thanks a lot Ignacio. It worked.
-----Original Message-----
Hi,

I do it all the time !

Did you tried it?

Just a comment, remember that you are getting the Item

property in this case
that is the indexer , therefore you have to write
reader["OrderNo"] using [] instead of ()

Hope this help,

--
Ignacio Machin,
ignacio.mach in AT dot.state.fl.us
Florida Department Of Transportation

"lakshmi" <lm@replytonews group.net> wrote in message
news:03******* *************** ******@phx.gbl. ..
Hi I'm using a SqlDataReader to read results from a SQL
view that returns 10 columns.
Is there anyway I can reader the columns based on their
names rather than their position?

strQuery = "SELECT customerid, orderno from orders where
orderID = 1";
SqlDataReader reader = cmd.ExecuteRead er();
while(reader.Re ad())
{
myOrderNo = reader.GetInt32 (1);
}

instead of using reader.GetInt32 (1), is there any syntax
that will support reader("OrderNo ") or something like that?
Thanks for your help.

.

Nov 15 '05 #4

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

Similar topics

6
363
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 in ADO.NET in MSDN and there is a confusion regarding the buffering of data in case of DATAREADER. The link for MSDN JAN 2004 is -
20
5530
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 "clean up" the DataView once it is not referenced and will not effect the number of connections to the database. A DataReader on the other hand always maintains a connection to the database and must be explicitly closed (Do not rely on garbage...
1
3090
by: Brent | last post by:
I'm having a hard time wrapping my head around how to build a multi-dimensional array of n length out of a DataReader loop. Take this pseudo-code: ======================================= public string get_array(string sql) { //create db connection & open
6
5454
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 in ADO.NET in MSDN and there is a confusion regarding the buffering of data in case of DATAREADER. The link for MSDN JAN 2004 is -
7
2903
by: Diffident | last post by:
Hello All, I would like to use DataReader based accessing in my Data Access Layer (DAL). What is considered to be a best practice while returning from a DAL method that executes a query and returns N rows. DataReader object? Collection object? DataTable object? Returning a DataReader object is not a good practice...right? Thnks for all your suggestions!!
0
8818
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9522
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9354
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9307
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9223
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8233
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6067
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3296
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.