Solved

VB.Net dataset index

Posted on 2003-10-26
8
7,445 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 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

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…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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