Creating a 'bookmark' in Ado.net - dataset

Windsailor

Well-known member
Joined
Aug 2, 2006
Messages
45
Programming Experience
1-3
Hello,

How do I create a 'bookmark' in a dataset so that I can return to that row after I have updated the database, cleared and re-filled the dataset?

I should say I want the bound datagrid or bound items on a form to return to that particular row after the dataset is filled that second time.

With a textbox that is databound to the PK in the dataset, I have tried:
VB.NET:
 Dim this As Integer
            this = Nothing
            this = Me.TextBox1.Text

            Me.DSCompetitors.Clear()
            Me.CompetitorsTableAdapter.Fill(Me.DSCompetitors.Competitors)
Dim foundRow As DataRow = Me.DSCompetitors.Tables("Competitors").Rows.Find(this)

If foundRow Is Nothing Then
                MsgBox("row not found")
            Else
                
            End If
The problem here is that when the 'click event' is over the bound datagrid returns to the first record, not the select row with the stored PK value.
How do I get the dataset to move to the record that has that PK value?

Thanks for your help and time.
 
Last edited:
VB.NET:
   this = Nothing
            this = Me.TextBox1.Text

            Me.DSCompetitors.Clear()
            Me.CompetitorsTableAdapter.Fill(Me.DSCompetitors.Competitors)
Dim foundRow As DataRow = Me.DSCompetitors.Tables("Competitors").Rows.Find(this)
 

If foundRow IsNot Nothing Then
Dim I As Integer = Me.DSCompetitors.Tables("Competitors").Rows.IndexOf(foundrow)
YourDataGridView.Rows(I).Selected = True
Else
MsgBox("row not found")

            End If
 
Cool.
Thank you very much.

I did find another way of doing this, but I like yours better...

VB.NET:
[FONT=Courier New][SIZE=2][FONT=Courier New][COLOR=blue][COLOR=blue]Dim[/COLOR][/COLOR] foundRow [COLOR=blue][COLOR=blue]As[/COLOR][/COLOR] DataRow = [COLOR=blue][COLOR=blue]Me[/COLOR][/COLOR].DSCompetitors.Tables([COLOR=#a31515][COLOR=#a31515]"Competitors"[/COLOR][/COLOR]).Rows.Find(this)[/FONT][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][FONT=Courier New][COLOR=blue][COLOR=blue]Me[/COLOR][/COLOR].CompetitorsBindingSource.CurrencyManager.Position = foundRow.Table.Rows.IndexOf(foundRow)[/FONT][/SIZE][/FONT]

That took me about 5 hrs to scratch out...:eek:

I think I'll stick around this forum.:D
 
I'd like to point out here that there isnt necessarily a corollorary between the bindingsource position and the datatable row number

A BS can have a filter or an order that means that it may be impossible to set .Position to e.g. 65, on a 70-row datatable, if 20 rows have been filtered out. Sorting too, happens in the DataRowView (what the BS links through to get the data) so it might be that the DataTable row #65 appears at position #20..

Its good that it works for you in this one case, but it may not always do so. Perhaps if you could explain what youre trying to do, we could help point out a way to do it properly..
 
I was more curious to see why he was updating, clearing and re-filling.. For the most part, a pointless, resource wasting excercise..
 
Its good that it works for you in this one case, but it may not always do so. Perhaps if you could explain what youre trying to do, we could help point out a way to do it properly..

Hello cjard,

There is a filter with the sql string on the dataset (basic ASC sort).
The thought was to return to the original record after updating the database, no matter where it is in the sort order (if it still exists).
I haven't played with it much to see where it would fail...
Originally I wanted to use the currencymanager or bindingsource so that all databound items would change to the correct record, not just the datagrid.
The datagrid was used to set up the example.

Good point about the clearing and refilling... what do you suggest?
 
I was more curious to see why he was updating, clearing and re-filling.. For the most part, a pointless, resource wasting excercise..

Actually the reason why I was doing this was to refresh the dataset with the new entries and have the correct sort order.

--Edit--

Basically I have to update after every edit and then refresh the query. Just incase of power failure which has happened.
Once the editing sequence starts, it continues at a fairly rapid pace.
 
Last edited:
mmm, but Update only makes the database the same as what you see, so I fail to understand what is gained by clear/refill

You have 10 rows, you edit them on screen, and your client and db go out of sync. You and save them.. Now your database and client app are in sync.

If you reload them, youre only going to get the same 10 rows you did before, in the same order, i.e. they are in sync again.. so why sync twice?

I dont know much about your app, if I knew more, maybe I'd understand better; theres still some missing link for my thinking, but if youre happy that it works as you want it to, then great! :D

ps;
If all controls go through the same bindingsource then they will all update to show the new current record if it changes... This is a separate issue to the updating..
 
This is for a small sporting app. Each contestant (when the 'event' starts) can come up and change their 'value', delete their 'value', change their event to another one etc. This all has to be updated, saved after every edit. And once the event starts it is constantly changing and has to be in sequence.

If you have more than one person (computer) editing these records, each person needs to see the very latest update, insert, deletions. It can get into a 'click happy' thing... sigh.

I have thought of using 'accept changes', 'get changes', but I was unsure if it would refill with the new rows etc. so clearing and refilling was an easy insurance thing...

What do you suggest?
 
Last edited:
ooops...
'GetChanges' has to do with updating a database, not retrieving...
I dont know what i was thinking there...:eek:

Getting back to the bookmark, why would someone want to put an alternative filter other than the original set up for the dataset?

Wouldn't it be easier just to set up another sorted dataset than hard code an additional filter? It seems it would be easier to maintain...
 
This is for a small sporting app. Each contestant (when the 'event' starts) can come up and change their 'value', delete their 'value', change their event to another one etc. This all has to be updated, saved after every edit. And once the event starts it is constantly changing and has to be in sequence.

What do you suggest?

If you want a realtime multi-client updating status board, dont bother with a database architecture on the client at all; Do it using Remoting from a server..

Imagine another app; suppose I said to you, I was going to write a chat client that, every second, did a SELECT * FROM messages WHERE recipient = <my id>

Would you think that a good way to do it? I dont.. And all modern chat clients connect to a server, and lsiten. When a message is sent to the server, the server dispatches it to the clients interested..

Clients do not continuously poll the server for new messages; huge waste of bandwidth and resources..
 
ooops...
'GetChanges' has to do with updating a database,

GetChanges simply returns you a sub-(DataSet/DataTable) containing only rows that have been changed in some way, since they were downloaded from the database. It has nothing to do with updating a database, but is often used (sometimes erroneously) to prepare a set of rows that a TableAdapter must send back to a database. This is usually pointless because a TA only sends rows that have changed anyway, but it is occasionally used to send only certain kinds of updates to a database.. e.g. only Deletions.


Getting back to the bookmark, why would someone want to put an alternative filter other than the original set up for the dataset?
Why do some managers ask for the moon on a stick?

Filtering results in the client has been available pretty much since the beginning of time. I'd say that quite a few people find a use for it; that youre not one of them right now doesnt necessarily mean you always will be!

Wouldn't it be easier just to set up another sorted dataset than hard code an additional filter? It seems it would be easier to maintain...
"Easier" in this context is probably subjective. I wouldnt go setting up another dataset, with 400 tables and 500 tableadapters just because I wanted one of the tables in a different order!
 
Back
Top