473,327 Members | 2,094 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,327 software developers and data experts.

Get One Value From DataTable

I'm just wondering if there is a faster way (better performance or fewer
lines of code) to retrieve one single value from a DataRow.

Here is what I'm currently doing when I just need a single integer value
from the DataRow:

int someID = 0;
if (DT.Rows.Count == 1) {
DataRow DR;
DR = DT.Rows[0];
someID= Convert.ToInt32(DR["SomeID"]);
}
Please note that I'm not using ExecuteScalar to retrieve one single value
from the underlying data source because I'm using many other columns in that
DataRow elsewhere in the same method.

Thanks!
Nov 17 '05 #1
2 42861
No need to create the DR object if you are not going to use it more than
once.

int someID = 0;
if (DT.Rows.Count == 1) {
someID= Convert.ToInt32(DT.Rows[0]["SomeID"]);
}
"Jordan Richard" <A@B.NET> wrote in message
news:ua**************@TK2MSFTNGP14.phx.gbl...
I'm just wondering if there is a faster way (better performance or fewer
lines of code) to retrieve one single value from a DataRow.

Here is what I'm currently doing when I just need a single integer value
from the DataRow:

int someID = 0;
if (DT.Rows.Count == 1) {
DataRow DR;
DR = DT.Rows[0];
someID= Convert.ToInt32(DR["SomeID"]);
}
Please note that I'm not using ExecuteScalar to retrieve one single value
from the underlying data source because I'm using many other columns in
that DataRow elsewhere in the same method.

Thanks!

Nov 17 '05 #2
But, he's not actually creating a DR object --- he's just briefly
storing a reference to one which already exists. In fact, the compiler
would probably generate identical IL for both versions.

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:#1**************@TK2MSFTNGP14.phx.gbl...
No need to create the DR object if you are not going to use it more than
once.

int someID = 0;
if (DT.Rows.Count == 1) {
someID= Convert.ToInt32(DT.Rows[0]["SomeID"]);
}

Nov 17 '05 #3

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

Similar topics

5
by: Stefan Turalski \(stic\) | last post by:
Hi, I'm wondering if there is a way to send a method parametrs by ref when DataTabel is a type of this value ? I done some sort of select over DataTable columns, just by removing them froma...
4
by: Stephen | last post by:
I am trying to add some code to below to include a datatable and fill the datatable. The reason for doing this is so as I can check to see whether there are any rows returned by the stored...
2
by: Newbie | last post by:
Im getting an exception: System.FormatException: Input string was not in a correct format. at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at...
1
by: Mike | last post by:
I have an ASP.NET/VB app that updates values in a DataTable over the course of about 3 different pages. On the way out of the first of these pages, I explicitly build the DataTable from values in...
0
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
0
by: Maart_newbie | last post by:
Hi all, I've got a question about returning the value of a pk-column to a DataTable after inserting a row (via a data-adapter) using MySql5. Here is the SQL and code concerned: ...
6
by: cj | last post by:
If I'm sitting on a datarow for a customer and want to change his phone number only if it's blank what would I write? if myDr("phone")= "" then myDr("phone") = "mphone" endif...
0
by: Dawnyy | last post by:
I have a typed dataset which I am populating using fill methods based on stored procedures. I have a form which contains a summary list of records and when a record is selected the detail of that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.