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

How to create a datatable object from a datarow [].


I have an array of datarow . Is there a performance efficient way of
deriving a datatable oject
containing only the rows in my array. ?

I want to avoid uding foreach .

Many thanks

JB
Nov 17 '05 #1
6 10939
where did you get the array of datarows?? the only way i know of is
looping through them and using dt.Rows.Add(...); if there's a better
way, i'd also like to know...

Nov 17 '05 #2
if there's a better
way, i'd also like to know...


Here is the code:

DataSet ds=GetDataSet();
DataTable dt=ds.Tables[0];

int i=5, j=11;

if(dt.Rows.Count-i>0)

{

DataRow[] selectedRows=new DataRow[(j-i)];

for(int index=0; index<selectedRows.Length; index++)

{

selectedRows[index]=dt.Rows[i+index];

}
return selectedRows;
Nov 17 '05 #3
Hi,

What about using a DataView ?

Cheers,

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

"jensen bredal" <je***********@yahoo.dk> wrote in message
news:e5**************@TK2MSFTNGP10.phx.gbl...
if there's a better
way, i'd also like to know...


Here is the code:

DataSet ds=GetDataSet();
DataTable dt=ds.Tables[0];

int i=5, j=11;

if(dt.Rows.Count-i>0)

{

DataRow[] selectedRows=new DataRow[(j-i)];

for(int index=0; index<selectedRows.Length; index++)

{

selectedRows[index]=dt.Rows[i+index];

}
return selectedRows;

Nov 17 '05 #4

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:uq*************@TK2MSFTNGP15.phx.gbl...
Hi,

What about using a DataView ?


Could you please explain based on the code posted earlier?

JB
Nov 17 '05 #5
Basically, it would be along the lines of:

DataSet ds=GetDataSet();
DataTable dt=ds.Tables[0];
DataView dv = new DataView(dt, "filter expression", "sort expression",
DataViewRowState.CurrentRows)
return dv;

where "filter expression" would be exactly as you'd write it in a WHERE
clause, and sort expression just as you'd write it in a ORDER BY.

Presumably, you have a better way of expressing the subset you want to
filter on, than "rows 5 thru 11"/
--
--
Truth,
James Curran
[erstwhile VC++ MVP]

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

"jensen bredal" <je***********@yahoo.dk> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:uq*************@TK2MSFTNGP15.phx.gbl...
Hi,

What about using a DataView ?


Could you please explain based on the code posted earlier?

JB

Nov 17 '05 #6
>
Presumably, you have a better way of expressing the subset you want to
filter on, than "rows 5 thru 11"/
--


That is the problem. I see no obvious way of doing this through a sort
expression.

5 through 11 is in fact almost what i'm trying to do. I have a datatable
with n rows.

each time i only wnat to subtract a subset and the nex subset the next time
and so on.
I see no obvious way to this with sql.
Do you?
JB
Nov 17 '05 #7

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

Similar topics

1
by: Al Bastido via .NET 247 | last post by:
could somebody please explain to me how the datatable.newrow method works, i've been trying to figure it out for weeks. I need to emulate it myself. I can bind my datagrid to a collection of...
2
by: Bajgon | last post by:
Hello, I have got a DataGrid and a DataTable, which is its DataSource. I can use DataTable.Rows.Find(key_value) method to locate any row in the DataTable, using values of key column. The...
1
by: Kelvin | last post by:
Hi All, I wrote a program insert new row between rows while the datatable is looping. It display the error message. Exception Details: System.ArgumentException: This row already belongs to this...
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...
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...
3
by: Gene Hubert | last post by:
I'm using DataTable.ImportRow to move data from one datatable to another... Dim dt, dtTarget As DataTable Dim dr As DataRow dt = DirectCast(Me.DataSource, DataTable) dtTarget = dt.Clone...
12
by: Doug Bell | last post by:
Hi, I am having problems trying to create a (temporary) DataTable from a selection from a DataGrid (dgOrders). dtOrdDetails is declared as a Public DataTable Sub is: Dim stFilter as String...
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...
6
by: Paulers | last post by:
Hello, I have a string that I am trying to add each char to a datatable row. for example if I have a string that looks like "abcdefg", I would like to break it up into an array of characters...
4
by: mojeza | last post by:
I would like to create generic object which will be used for store of single row of DataTable. Lets say I create class as follow: Public Class Participant Public ParticipantID As Int64 Public...
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...
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?

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.