467,923 Members | 1,187 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,923 developers. It's quick & easy.

ADO.NET, need to get index of datarow

BB
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
Nov 20 '05 #1
  • viewed: 2597
Share:
6 Replies
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

Nov 20 '05 #2
Cor
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.

Nov 20 '05 #3
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

.

Nov 20 '05 #4
* "BB" <an*******@discussions.microsoft.com> 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=microso ft.public.dotnet.framework.adonet>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
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" <an*******@discussions.microsoft.com> wrote in message
news:09****************************@phx.gbl...
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

Nov 20 '05 #6
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 willtell you any number of reasons why you don't need it - but you and I knowthat you do.

I wrote a function that will do this for you by returning the index of therow 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) AsInteger

' 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 returnedwith

' 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" <an*******@discussions.microsoft.com> wrote in messagenews:09****************************@phx.gbl...
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

.

Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mohammed Abdel-Razzak | last post: by
4 posts views Thread by marc.gibian | last post: by
11 posts views Thread by Tim Frawley | last post: by
1 post views Thread by Cordine | last post: by
8 posts views Thread by Sam | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.