Link to home
Start Free TrialLog in
Avatar of dwops
dwops

asked on

VB.Net dataset index

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
Avatar of the-edge
the-edge

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
Avatar of dwops

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of the-edge
the-edge

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dwops

ASKER

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



Avatar of dwops

ASKER

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
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
Avatar of dwops

ASKER

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.