?
Solved

How to find the row number of a datarow from a datatable ?

Posted on 2004-11-24
9
Medium Priority
?
466 Views
Last Modified: 2010-05-18
How to find the row number of a datarow from a datatable ?

For example:

Private sub test(byref inRow as datarow)
...
...
' how can I detect the row number of inRow here where inRow is a datarow from a datatable ?
end sub

0
Comment
Question by:vbhaha
  • 4
  • 3
  • 2
9 Comments
 
LVL 27

Expert Comment

by:Dabas
ID: 12672528
Hi vbhaha:
    A datarow does not "know" its position within the table.
    You would have to search your table for the row, but I have the feeling that is not your intention.

Dabas
0
 

Author Comment

by:vbhaha
ID: 12672574
Hi Dabas,

If it don't know its position, then the only thing I can do is to search the whole datatable before further process !!!

vbhaha
0
 
LVL 27

Expert Comment

by:Dabas
ID: 12672596
vbhaha:
That is right.

Question is, what exactly you want to do, and if there is not a more efficient way of doing it.
Why do you need to know the position within the table?

Dabas
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vbhaha
ID: 12672641
Actually, my application has two layers, UI layer and data update layer.

The UI layer handles all user actions, change, add, delete, move next, move previous (only one record will be changed each time),

After the user press "Update" button, it will pass the datatable into update layer for updating, if I know the row position then I don't need to search the whole datatable.

0
 
LVL 27

Expert Comment

by:Dabas
ID: 12672654
vbhaha:
If your table is indexed, then you should be able to use an INSERT, UPDATE or DELETE SQL statement to do your updating.
No need to know the position of your row in the table.

Dabas
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12672691
What do you want to do When you get the Row Number of that particular DataRow within the dataTable ???

Whetever information you can get from the dataTable is probably already there in the dataRow.

Also How is this dataRow created, is it in Sync with the DataTable ??

0
 
LVL 27

Expert Comment

by:Dabas
ID: 12672714
vbhaha:
By the way vbhaha, you seem to have an awful grading reputation!
Any reason why you give out so many B and C grades?

Dabas
0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 750 total points
ID: 12672717
What I meant with dataRow being in Sync was if the dataRow has been instantiated from the same dataTable then we can search using a key field

eg.

Dim DV As DataView = New DataView(YourDataTable, "", "Key_Field_Name", DataViewRowState.CurrentRows)
Dim RowNo as Integer
RowNo  = DV.Find(YourDataRow("Key_Field_Name")

This will give you the Row No of the DataRow within the DataTable

0
 

Author Comment

by:vbhaha
ID: 12672722
vbhaha:
If your table is indexed, then you should be able to use an INSERT, UPDATE or DELETE SQL statement to do your updating.
No need to know the position of your row in the table.

Dabas
--------------------------------------------------------------------------------
For simple updating you're right, however if the program need to update other tables then ....!

For example:

After update the invoice details (with product no, qty), then it also needs to update the product table for +/- the quantity, OR for writing insertion log/deletion log ...etc

That why I need to know which row has been updated...!

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question