473,382 Members | 1,710 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,382 software developers and data experts.

Best way to populate an object from a datareader

I may be going a bit crazy, but could someone please give me a
definitve way to poplate an object from an SqlDataReader. Do i use
DataReader.GetString(0) with check for dbnull or
Convert.ToString(dr[0]) or is there a better way?

Oct 17 '06 #1
2 1647

See
5/24/2006 ENTRY
http://sholliday.spaces.live.com/blog/
Custom Objects/Collections and Tiered Development

In the code, I use an IDataReader .. the "Get" methods, to populate objects
and collections.

You should use the explicit datatype if you know it.

GetString
GetDecimal
GetDateTime

If you' dont know it, you can use the generic GetValue ~TO FIGURE OUT THE
DATATYPE, but not as the final solution.


"Damian" <da**********@yahoo.co.ukwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
I may be going a bit crazy, but could someone please give me a
definitve way to poplate an object from an SqlDataReader. Do i use
DataReader.GetString(0) with check for dbnull or
Convert.ToString(dr[0]) or is there a better way?

Oct 17 '06 #2
Thanks

Oct 18 '06 #3

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

Similar topics

9
by: Mike L | last post by:
I tried a sample of code in MSDN magazine, but now I'm stuck. What code has the best performance to populate a Data Grid with a SP? Below is the code I have, which might be completing the wrong...
7
by: Cory Toms | last post by:
Hey All, I have question about the best way to go about doint this: SqlDataReader _dr=components.getItems(); fooclass _myarray = new fooclass; //create new array of my class int i=0; ...
3
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to...
2
by: Jim via DotNetMonster.com | last post by:
Hi, I'm passing a variable to another page through a querystring. I then want to use that variable to retrieve records from a database to poulate a dropdownlist. I can read the variable from the...
3
by: Jerry | last post by:
Hello everyone! I'm trying to populate a dropdown list from SQL Server but it's not being populated. I've tried all sorts of suggestions and examples that I found from Google but I just can not...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
3
by: rn5a | last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB table. The records retrieved depends upon 2 conditions (the conditions depend on what a user selects in an ASPX page). If...
0
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
1
by: MastaKay | last post by:
I hv dropdownlist on a c# page connected to a database(MS Access). I want to get values onto my datagrid when I select a value from the dropdownlist.The Item I select from the dropdown will...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: 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...

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.