473,587 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Smart DataReader!!

Hi All, Whenever I use the SqlDataReader I have to retrieve a column by its
OrdinalPosition can't I do something like this

using(SqlDataRe daer sr=SqlHelper.Ex ecuteReader(... .))
{
while(sr.Read() )
string x=sr.GetValue(" Column1").ToStr ing();
// right now I have to do sr.GetValue(1). ToString();
}

TIA
Feb 9 '07 #1
1 2282
Hi,

"Vai2000" <no****@microso ft.comwrote in message
news:u2******** ********@TK2MSF TNGP06.phx.gbl. ..
| Hi All, Whenever I use the SqlDataReader I have to retrieve a column by
its
| OrdinalPosition can't I do something like this
|
| using(SqlDataRe daer sr=SqlHelper.Ex ecuteReader(... .))
| {
| while(sr.Read() )
| string x=sr.GetValue(" Column1").ToStr ing();
| // right now I have to do sr.GetValue(1). ToString();
| }

try sr["Column1"]

Regarding the ToString() or in general converting the readed field to the
final type you have to do it always. The reason is that the indexer return
an object wich you need to cast (or convert) to your intended type.
--
Ignacio Machin
machin AT laceupsolutions com
Feb 9 '07 #2

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 -
6
750
by: Ravi | last post by:
Hi, I am not able to understand why a datareader needs a connection to the DB all the time. Here is what I tried. Sqlcommand cmd = ("select * from table1",con) // where con is the connection object 1. DataReader dr = cmd.executereader(); 2.while(dr.read()) { // do something //} I have a break point in line 2. when i run my application and...
5
5751
by: Jason Huang | last post by:
Hi, Is it possible to bind DataReader to a DataGrid in C# windows form? And how? And can we update data in a DataSet by using the DataReader? Thanks for help. Jason
20
5522
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...
2
1571
by: Andrei Pociu | last post by:
In a typical ASP .NET Web Application (website), I'm currently using a class where I declare some public static objects. For example there's the place where I initialize the SqlConnection. Also there's the place where I declare one public static DataReader, but I'm not sure this is the best way to do it. I use that DataReader in all the...
1
3087
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
7
3390
by: Varangian | last post by:
Hi all, the question I want to ask if the conversion of a DataReader to a Table looping through the DataReader is better than using the Fill Method of the DataAdapter... I'm asking because internally the DataAdapter uses the DataReader... so whats the deal of writing a method that converts a DataReader into a DataTable ? Thanks!
7
2902
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...
3
3380
by: Johnny Jörgensen | last post by:
I've got an error that I simply cannot locate: I've got a form in which I use a datareader object to read information from a db. After the read, I close the reader and I dispose of both the reader and the command object (but don't close the connection which is public in the solution). The first time i open my form from a parent form,...
0
7843
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...
0
8339
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...
1
7967
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...
0
8220
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...
0
6619
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...
0
5392
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...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
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

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.