Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VB.Net dataset index

Posted on 2003-10-26
8
7,438 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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