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 6 10954
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...
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.Coun t-i>0)
{
DataRow[] selectedRows=ne w DataRow[(j-i)];
for(int index=0; index<selectedR ows.Length; index++)
{
selectedRows[index]=dt.Rows[i+index];
}
return selectedRows;
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******** ******@TK2MSFTN GP10.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.Coun t-i>0)
{
DataRow[] selectedRows=ne w DataRow[(j-i)];
for(int index=0; index<selectedR ows.Length; index++)
{
selectedRows[index]=dt.Rows[i+index];
}
return selectedRows;
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:uq******** *****@TK2MSFTNG P15.phx.gbl... Hi,
What about using a DataView ?
Could you please explain based on the code posted earlier?
JB
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",
DataViewRowStat e.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******** ******@TK2MSFTN GP12.phx.gbl... "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote in message news:uq******** *****@TK2MSFTNG P15.phx.gbl... Hi,
What about using a DataView ?
Could you please explain based on the code posted earlier?
JB
> 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 objects with no problem. But that leaves me with a fixed number of properties per object and therefore a fixed number of columns in my datagrid.
I wanted to do something similar to the datatable, where you add columns then have a method that generates...
|
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 result is a DataRow
object.
How to find and select the current position of this DataRow in
the DataGrid control?
|
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 table.
System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID,
Int32 pos) +319
System.Data.DataRowCollection.Add(DataRow row) +14
|
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 System.String.System.IConvertible.ToInt32(IFormatProvider provider) at
System.Convert.ToInt32(Object value) at
System.Data.Common.Int32Storage.Set(Int32 record, Object value) at
System.Data.DataColumn.set_Item(Int32 record, Object value)Couldn't store
<BILLABLE...
|
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 datacolumns do not trigger
their expression when other columns from which the expressions are derived
are updated. Below is a basic example of what I am doing.
User enters values into an asp.net form and clicks a button.
Retrieve dataset from...
| |
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 'copy the data structure
dtTarget.DefaultView.Sort = String.Empty 'remove the sort
|
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
Dim OrdersRows() as DataRow
|
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 the column order of the
datatable). I also allow the user to click on a column header to sort the
datagrid by that column.
I need to identify the row and column in the datatable when the user clicks
on a cell in the datagrid.
Using the...
|
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 so I can do this:
myDataTable.Rows.Add(array())
instead of myDataTable.Rows.Add("a","b","c","d","e","f","g")
|
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 LastName As String
Public FirstName As String
End Class
then I get a data from the database to DataTable and create array of
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |