473,568 Members | 3,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading result from DB reader


What is the nicest way to read Database data from reader objecy after making
a SQL query? Do I really need mapper classes with methods like:

// Reader is OleDbDataReader object.
public int GetInt(string column)
int data = (reader.IsDBNul l(reader.GetOrd inal(column)))
? (int) 0 : (int)reader[column];
return data;

or does C#/dotNET provide any elegant solutions for checking null fields
etc. by it's own?

Jan 26 '06 #1
2 1787
Well, if you are just going to cast via the indexer, you could use

Get<T>(string column) and replace all "int" with T

Personally I'd also call GetOrdinal once (at the top) to get the index, and
use this (rather than the string) to get the value
If you want specific versions I'd use reader.GetInt32 (columnIndex)

Jan 26 '06 #2
But to answer your original question; not much more elegant than your
example unless I've just missed 'em.

Jan 26 '06 #3

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

Similar topics

by: Drew Yallop | last post by:
I read an XML file with a stream reader in VB.Net. When I look at the stream reader output in debug mode (by passing cursor over the stream reader object)the format is a perfect replica of the file as displayed when I open the xml file in VS .net 2003 IDE. When I perform the same procedure in C# the stream reader obkect displays a chaotic...
by: Cool Guy | last post by:
I use the following method to read a file: static byte ReadFile(string path) { FileStream stream = new FileStream(path, FileMode.Open); BinaryReader reader = new BinaryReader(stream); byte result = reader.ReadBytes((int)stream.Length); reader.Close(); return result;
by: Mattyw | last post by:
Hi I have a sqlcommand that returns all the rows in a column and then pass that to a datareader. I am new to VS.Net and so far I can only return the first row in the first column using label1.text = reader(0).tostring
by: simon | last post by:
What is the best way to read the values from the datatbase. I have sql="SELECT userName, userCountry, userVisit from users where userID=2" Create a command object? Dim oCmd As SqlCommand oCmd = New SqlCommand(sql, Connection) object = oCmd.ExecuteScalar() oCmd.Connection.Close()
by: Joe | last post by:
Anyone can suggest the best method of reading XML and adding data to ListView? Here is the xml data structure:: <xml> <site> <url>http://www.yahoo.com</url> <lastupdate></lastupdate> <check>1</check>
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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...
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...
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...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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...

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.