Solved

VB.Net dataset index

Posted on 2003-10-26
8
7,433 Views
Last Modified: 2012-06-27
hey, i'm wondering how to get the current row that a dataset is on.  
I assume the dataset maintains some kind of cursor index of which row is currently being inserted, deleted , edited, viewed etc...
is there  a way to get that row's index?

i'm looking for a solution in vb.net

thanks
-dwops
0
Comment
Question by:dwops
  • 4
  • 4
8 Comments
 
LVL 3

Expert Comment

by:the-edge
ID: 9625733
take a look at this piece of the article "introduction to dataset" in the msdn help:

<<Record Position and Navigation in Datasets
Because a dataset is a fully disconnected container for data, datasets (unlike ADO recordsets) do not need or support the concept of a current record. Instead, all records in the dataset are available.

Because there is no current record, there is no specific property that points to a current record and there are no methods or properties for moving from one record to another. (In contrast, ADO recordsets support an absolute record position and methods to move from one record to the next.) You can access individual tables in the dataset as objects; each table exposes a collection of rows. You can treat this like any collection, accessing rows via the collection's index or using collection-specific statements in your programming language.>>

however you can check the state of a row with the DataRow.RowState Property to determine if it was inserted, deleted , edited, viewed etc since dataset was filled with a DataAdapter

you can also create a data view of a dataset that filters based on row state and get only the rows that have the rowstate property you use in the filter of the dataview

hope this is useful

the edge
0
 
LVL 1

Author Comment

by:dwops
ID: 9627409
i have multiple datagrids all displaying data from the same dataset, if i click around on one datagrid, i can see the row change in all other grids.  if i have textboxes also bound to this dataset, their values change to whatever record has been clicked in the datagrid.  

So, am I correct in saying that there is NO WAY to figure out which row is the current row by referencing the dataset only?  How about using a currency manager or something?
0
 
LVL 3

Accepted Solution

by:
the-edge earned 125 total points
ID: 9627565
IMHO yes: there is NO WAY to figure out which row is the current row by referencing the dataset only.
but you can use the currencymanager.position property to get the current row selected in a datagrid, it should correspond to the dataset row currently displayed.
use something like dataset.tables(0).rows(currencymanager.position) to refer at the displayed row (i've haven't try it yet, i'll try tonigth and post a more detailed example).

the edge
0
 
LVL 1

Author Comment

by:dwops
ID: 9628895
thanks edge,

i'm pretty sure your right.  my problem here is that i'm using a datagrid that might not necessarily correspond with the dataset (ie row i in the grid might not be row i in the dataset)

i'm gonna let this post sit for a short while and let some more ideas come out... if it is indeed impossible, i'll dish you out the points for showing me that.

of course, if you could somehow show more info to prove it impossible, i'll dish the points immediately.

thanks
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 3

Expert Comment

by:the-edge
ID: 9630643
you say your datagrid not necessarily correspond with the dataset, but previously you said that you have multiple datagrids all displaying data from the same dataset.
if you use a dataset as datasource of a datagrid, the data displayed in the datagrid must correspond to data stored in dataset and the relative currencymanager show the row currently displayed by the .position property.

However you can use the row's find method or the table's select method to retrieve the dataRow that match your search criteria:
for example if the primary key of your currently selected datagrid's row is "25" then you can use

myDataSet.Tables(0).Rows.Find(25)

to get the corresponding row of the dataset.


more, if you haven't the primary key value, you can use

myDataSet.Tables(0).Select(FilterExpression)

it returns an array of datarow that match your filter expression.


in your initial post you wrote:
"I assume the dataset maintains some kind of cursor index of which row is currently being inserted, deleted , edited, viewed etc...
is there  a way to get that row's index?"

maybe the dataset don't maintains an index of row currently being inserted, deleted , edited, viewed
but only marks these rows with something for identifying them when it needs.

bye

the edge



0
 
LVL 1

Author Comment

by:dwops
ID: 9636688
hey edge, thanks for your help.  my goal is still just to maintain an index of the current record as it is in the dataset, by referencing the dataset.  i apologize if my different examples (ie using 2 grids, using a grid whose rows are not in the same order as the dataaset) got confusing, my bad. my only goal is to get the dataset index.

i realize that this functionality just isn't supported by the dataset.  my alternative, which really isn't what i want to do, was to create an invisible list box bound to the dataset.  this listbox will be in the same order as the dataset, so the indexes are the same, also, the currency manager moves the index in the listbox along with the dataset.  i can reference the current index of the listbox and this will always be the same as the dataset... oh well, this works fine for now.

thanks for your help

dwops
0
 
LVL 3

Expert Comment

by:the-edge
ID: 9637863
so, wath do you exactly mean when you say your goal is to maintain an index of the current record?
what do you want to know is just the position of the last record added?
please explain me this, maybe we can find another solution togheter.

bye

the edge
0
 
LVL 1

Author Comment

by:dwops
ID: 9645567
hey, sorry i haven't given out the points, here they are.

i guess my issue is sort of confusing, but you still answered it.  thanks for your help.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now