PC Review


Reply
Thread Tools Rate Thread

DataRow Index

 
 
Mauricio
Guest
Posts: n/a
 
      7th Nov 2003
How can I know the index of a DataRow that belongs to a
DataTable ?
I have the DataRow and I want your Rows' index.

Tanks.

Mauricio (Brazil)
 
Reply With Quote
 
 
 
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      7th Nov 2003
The ordinal? The number of the row in the Rows collection? The Value of the
PK column?

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Mauricio" <(E-Mail Removed)> wrote in message
news:028f01c3a558$9bfbee70$(E-Mail Removed)...
> How can I know the index of a DataRow that belongs to a
> DataTable ?
> I have the DataRow and I want your Rows' index.
>
> Tanks.
>
> Mauricio (Brazil)



 
Reply With Quote
 
naidu
Guest
Posts: n/a
 
      8th Nov 2003
No not the The Value of the PK column
how do we get the ordinal, the number of the row in the
Rows collection.

 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      9th Nov 2003
The Ordinal property?

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"naidu" <(E-Mail Removed)> wrote in message
news:06b801c3a5ce$1e013ef0$(E-Mail Removed)...
> No not the The Value of the PK column
> how do we get the ordinal, the number of the row in the
> Rows collection.
>



 
Reply With Quote
 
Bernie Yaeger
Guest
Posts: n/a
 
      9th Nov 2003
Hi Mauricio,

Develop a dataview of the table and then you will get the index. Here's how
it works:

Dim arrayseeks(0) As Object

Dim ifinds As Integer

Dim vues As New DataView(dsshipcode.Tables(0))

vues.Sort = "shipcode"

Dim irow as datarow

For Each irow In dsshipcode.Tables(0).Rows

arrayseeks(0) = "12345"

ifinds = vues.Find(arrayseeks)

If ifinds <> -1 Then ' ie, found it

mdescrip = vues(ifinds)("descrip")

Else

mdescrip = ""

End If

Next

In this code, ifind in the index of the found row. I suspect this is what
you were after.
HTH,
Bernie Yaeger

"Mauricio" <(E-Mail Removed)> wrote in message
news:028f01c3a558$9bfbee70$(E-Mail Removed)...
> How can I know the index of a DataRow that belongs to a
> DataTable ?
> I have the DataRow and I want your Rows' index.
>
> Tanks.
>
> Mauricio (Brazil)



 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      10th Nov 2003
Thanks for Bernie's response.

Hi Mauricio,

Assuming that you have both references to the DataTable and DataRow
objects, and the DataRow is in DataTable.Rows collection, you can also use
Ojbect.ReferenceEquals method to get the index. Here's an example:

private int FindIndex(DataTable dt, DataRow dr)
{
for(int i=0;i<dt.Rows.Count;i++)
if(Object.ReferenceEquals(dt.Rows[i], dr))
return i;
return -1;
}

For more information about Object.ReferenceEquals, please refer to the
following:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemobjectclassreferenceequalstopic.asp

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "Bernie Yaeger" <(E-Mail Removed)>
| References: <028f01c3a558$9bfbee70$(E-Mail Removed)>
| Subject: Re: DataRow Index
| Date: Sat, 8 Nov 2003 23:48:44 -0500
| Lines: 49
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: ool-18b80c4e.dyn.optonline.net 24.184.12.78
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:65860
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Hi Mauricio,
|
| Develop a dataview of the table and then you will get the index. Here's
how
| it works:
|
| Dim arrayseeks(0) As Object
|
| Dim ifinds As Integer
|
| Dim vues As New DataView(dsshipcode.Tables(0))
|
| vues.Sort = "shipcode"
|
| Dim irow as datarow
|
| For Each irow In dsshipcode.Tables(0).Rows
|
| arrayseeks(0) = "12345"
|
| ifinds = vues.Find(arrayseeks)
|
| If ifinds <> -1 Then ' ie, found it
|
| mdescrip = vues(ifinds)("descrip")
|
| Else
|
| mdescrip = ""
|
| End If
|
| Next
|
| In this code, ifind in the index of the found row. I suspect this is what
| you were after.
| HTH,
| Bernie Yaeger
|
| "Mauricio" <(E-Mail Removed)> wrote in message
| news:028f01c3a558$9bfbee70$(E-Mail Removed)...
| > How can I know the index of a DataRow that belongs to a
| > DataTable ?
| > I have the DataRow and I want your Rows' index.
| >
| > Tanks.
| >
| > Mauricio (Brazil)
|
|
|

 
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
ADO.NET, need to get index of datarow BB Microsoft VB .NET 7 17th Nov 2005 02:53 AM
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
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 07:53 AM.