PC Review


Reply
Thread Tools Rate Thread

ADO.NET, need to get index of datarow

 
 
BB
Guest
Posts: n/a
 
      25th Nov 2003
Hello all,

I am using the currency manager in VB to navigate a
dataset. I know how to use .position to loop through the
rows, but what I want to do is *get* the position of the
row I just added/updated, so that I can reposition the
currency manager there sometime later.

Seems like after I add a detached datarow to the
datatable, that index should be sitting there somewhere
for me to grab, but I don't see where that is in either
the currency manager, the dataset itself, etc. I can
always redo the i/o to re-retrieve the datarow, but that
seems like a waste.

Any ideas?

TIA,

BB
 
Reply With Quote
 
 
 
 
One Handed Man
Guest
Posts: n/a
 
      25th Nov 2003
Suggest you repost this 'Q' to adonet newsgroup.

Regards - OHM


BB wrote:
> Hello all,
>
> I am using the currency manager in VB to navigate a
> dataset. I know how to use .position to loop through the
> rows, but what I want to do is *get* the position of the
> row I just added/updated, so that I can reposition the
> currency manager there sometime later.
>
> Seems like after I add a detached datarow to the
> datatable, that index should be sitting there somewhere
> for me to grab, but I don't see where that is in either
> the currency manager, the dataset itself, etc. I can
> always redo the i/o to re-retrieve the datarow, but that
> seems like a waste.
>
> Any ideas?
>
> TIA,
>
> BB



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      25th Nov 2003
Hi BB,

The currency manager gives you the current row on your control
(so I thought that you don't have to use a loop for updating)
The last added row in a dataset is as far as I know always
dataset.tables(x).rows.count - 1

And if you want to know a row you are updating using a loop, why not just
use a loop like
\\\
dim i as integer
for i = 1 to dataset.tables(x).rows.count - 1
do something with the found row
datset.tables(x).rows(i).item("myitem") etc
if found lastrow = i
exit for
next
///
I hope this was where you was after?

Cor

>
> I am using the currency manager in VB to navigate a
> dataset. I know how to use .position to loop through the
> rows, but what I want to do is *get* the position of the
> row I just added/updated, so that I can reposition the
> currency manager there sometime later.
>
> Seems like after I add a detached datarow to the
> datatable, that index should be sitting there somewhere
> for me to grab, but I don't see where that is in either
> the currency manager, the dataset itself, etc. I can
> always redo the i/o to re-retrieve the datarow, but that
> seems like a waste.
>



 
Reply With Quote
 
Guest
Posts: n/a
 
      25th Nov 2003
Good advice for a newbie...thanks.

>-----Original Message-----
>Suggest you repost this 'Q' to adonet newsgroup.
>
>Regards - OHM
>
>
>BB wrote:
>> Hello all,
>>
>> I am using the currency manager in VB to navigate a
>> dataset. I know how to use .position to loop through

the
>> rows, but what I want to do is *get* the position of

the
>> row I just added/updated, so that I can reposition the
>> currency manager there sometime later.
>>
>> Seems like after I add a detached datarow to the
>> datatable, that index should be sitting there somewhere
>> for me to grab, but I don't see where that is in either
>> the currency manager, the dataset itself, etc. I can
>> always redo the i/o to re-retrieve the datarow, but

that
>> seems like a waste.
>>
>> Any ideas?
>>
>> TIA,
>>
>> BB

>
>
>.
>

 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      25th Nov 2003
* "BB" <(E-Mail Removed)> scripsit:
> I am using the currency manager in VB to navigate a
> dataset. I know how to use .position to loop through the
> rows, but what I want to do is *get* the position of the
> row I just added/updated, so that I can reposition the
> currency manager there sometime later.
>
> Seems like after I add a detached datarow to the
> datatable, that index should be sitting there somewhere
> for me to grab, but I don't see where that is in either
> the currency manager, the dataset itself, etc. I can
> always redo the i/o to re-retrieve the datarow, but that
> seems like a waste.


..NET + Database group:

<news://msnews.microsoft.com/microsoft.public.dotnet.framework.adonet>

Web interface:

<http://msdn.microsoft.com/newsgroups/default.asp?url=/newsgroups/loadframes.asp?icp=msdn&slcid=us&newsgroup=microsoft.public.dotnet.framework.adonet>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
Bernie Yaeger
Guest
Posts: n/a
 
      25th Nov 2003
Hi BB,

Not too many people know how to get a row index using ado .net and many will
tell you any number of reasons why you don't need it - but you and I know
that you do.

I wrote a function that will do this for you by returning the index of the
row in question. Note that in the code below 'functions' is a class in a
..dll called 'imcfunctionlib'.
Public Function findindex(ByVal dt As DataTable, ByVal dr As DataRow) As
Integer

' signature:

' dim funcs as new imcfunctionlib.functions

' dim xint as integer

' xint = funcs.findindex(dsmanifest.tables(0),irow)

' when you call findindex inside a loop the current irow index is returned
with

' idex = findindex(ods.Tables(0), irow)

' at the same time, this

' MessageBox.Show(irow("imcacct"))

' equals

' MessageBox.Show(ods.Tables(0).Rows(idex)("imcacct"))

' once outside the loop - see dataworks for more info

Dim i As Integer

For i = 0 To dt.Rows.Count - 1

If Object.ReferenceEquals(dt.Rows(i), dr) Then

Return i

End If

Next

Return -1

End Function

HTH,

Bernie Yaeger

"BB" <(E-Mail Removed)> wrote in message
news:098701c3b36e$b0a8c1d0$(E-Mail Removed)...
> Hello all,
>
> I am using the currency manager in VB to navigate a
> dataset. I know how to use .position to loop through the
> rows, but what I want to do is *get* the position of the
> row I just added/updated, so that I can reposition the
> currency manager there sometime later.
>
> Seems like after I add a detached datarow to the
> datatable, that index should be sitting there somewhere
> for me to grab, but I don't see where that is in either
> the currency manager, the dataset itself, etc. I can
> always redo the i/o to re-retrieve the datarow, but that
> seems like a waste.
>
> Any ideas?
>
> TIA,
>
> BB



 
Reply With Quote
 
Guest
Posts: n/a
 
      26th Nov 2003
Bernie, this was a big help. Thanks.

>-----Original Message-----
>Hi BB,
>
>Not too many people know how to get a row index using

ado .net and many will
>tell you any number of reasons why you don't need it -

but you and I know
>that you do.
>
>I wrote a function that will do this for you by

returning the index of the
>row in question. Note that in the code

below 'functions' is a class in a
>..dll called 'imcfunctionlib'.
>Public Function findindex(ByVal dt As DataTable, ByVal

dr As DataRow) As
>Integer
>
>' signature:
>
>' dim funcs as new imcfunctionlib.functions
>
>' dim xint as integer
>
>' xint = funcs.findindex(dsmanifest.tables(0),irow)
>
>' when you call findindex inside a loop the current irow

index is returned
>with
>
>' idex = findindex(ods.Tables(0), irow)
>
>' at the same time, this
>
>' MessageBox.Show(irow("imcacct"))
>
>' equals
>
>' MessageBox.Show(ods.Tables(0).Rows(idex)("imcacct"))
>
>' once outside the loop - see dataworks for more info
>
>Dim i As Integer
>
>For i = 0 To dt.Rows.Count - 1
>
>If Object.ReferenceEquals(dt.Rows(i), dr) Then
>
>Return i
>
>End If
>
>Next
>
>Return -1
>
>End Function
>
>HTH,
>
>Bernie Yaeger
>
>"BB" <(E-Mail Removed)> wrote in

message
>news:098701c3b36e$b0a8c1d0$(E-Mail Removed)...
>> Hello all,
>>
>> I am using the currency manager in VB to navigate a
>> dataset. I know how to use .position to loop through

the
>> rows, but what I want to do is *get* the position of

the
>> row I just added/updated, so that I can reposition the
>> currency manager there sometime later.
>>
>> Seems like after I add a detached datarow to the
>> datatable, that index should be sitting there somewhere
>> for me to grab, but I don't see where that is in either
>> the currency manager, the dataset itself, etc. I can
>> always redo the i/o to re-retrieve the datarow, but

that
>> seems like a waste.
>>
>> Any ideas?
>>
>> TIA,
>>
>> BB

>
>
>.
>

 
Reply With Quote
 
New Member
Join Date: Nov 2005
Posts: 1
 
      17th Nov 2005
Also here can be used search abilities of an ArrayList container that presented by List property of DataRowCollection(IndexOf, BinarySearch..). DataRowCollection is returned by DataTable->Rows property. To access protected member without compiler's modifications lets doing something like this:

#pragma warning( disable : 4669)

public __gc class ListPropertyPublicRowCollection: public System:ata:ataRowCollection
{
public: inline static GetRowIndex(DataRowCollection* rc, DataRow* dr)

{ return reinterpret_cast<ListPropertyPublicRowCollection*>(rc)->List->IndexOf(dr);}
};


or like this

public __gc class ListPropertyPublicRowCollection: public System:ata:ataRowCollection
{
public: __property virtual ArrayList* get_List(){return DataRowCollection::get_List();}

};

...

reinterpret_cast<ListPropertyPublicRowCollection*>(myDataTable->Rows)->List->IndexOf(myDataRow);

choose that you like.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataRow index within a DataRowCollection Brian Microsoft ADO .NET 1 28th Sep 2005 08:52 PM
enum as index for DataRow marc.gibian@ACM.ORG Microsoft C# .NET 1 13th Jan 2005 05:02 PM
DataRow index Nabeel Moeen Microsoft Excel Programming 2 27th Feb 2004 01:18 PM
DataRow Index Mauricio Microsoft ADO .NET 5 10th Nov 2003 01:30 AM
Finding a DataRow index William Ryan Microsoft ADO .NET 3 26th Aug 2003 11:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:33 AM.