?
Solved

VB.Net dataset index

Posted on 2003-10-26
8
Medium Priority
?
7,451 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
[X]
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
  • 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 500 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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