how to position to a row in a table

G

Guest

I've been trying to move to the last row of a table. The
connection, dataadapter, dataset and so on have all been
created in code. The examples of moving position in all
the books I've read are for navigation controls in forms,
and include bindingcontext. I need to find a value for a
column in the last row of a table where there is no form
or controls in which these values are displayed.

For example:

Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button1.Click

'Move to first position
Me.BindingContext(das1, "Shippers").Position _
= 0

End Sub

Private Sub Button2_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button2.Click

'Move to previous position
Me.BindingContext(das1, "Shippers").Position _
-= 1

End Sub

Private Sub Button3_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles Button3.Click

'Move to next position
Me.BindingContext(das1, "Shippers").Position _
+= 1

End Sub

Private Sub Button4_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click

'Move to last position
Me.BindingContext(das1, "Shippers").Position = _
Me.BindingContext(das1, "Shippers").Count - 1

End Sub

How do I get to a position without a bindingcontext?

thanks,

Dennist
 
C

CT

Dennist,

That'll be quite hard to accomplish, since there are no cursors in the
DataTable class. The BindingContext and the CurrencyManager implement this
functionality for you. However, one thing you could do is to use a DataView,
and filter the last row (using the RowFilter property), if you have a column
value that you can use an aggregate function on, such as MAX. This obviously
depends on how the data is sorted, but you might want to apply the right
sorting on the DataView (using the Sort property), if not already done when
retrieved from the data store.
 
G

Guest

Thanks, CT. The section on DataView in Chapter 8 of
ado.net core reference will be some going. vb.net has
lost much of it's rad features, I'm afraid. It seems to
me I'll have to clear the dataset and refill it. Am I
right?

dennist
 
K

Kevin Yu [MSFT]

Hi Dennist,

You needn't refill the dataset. You can create another DataView from the
DataTable by calling the constructor of DataView, and get the last record.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: <[email protected]>
| Sender: <[email protected]>
| References: <[email protected]>
| Subject: how to position to a row in a table
| Date: Tue, 4 Nov 2003 02:38:30 -0800
| Lines: 7
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOiv8m11ZdPAEukTOSNSiutxk9slA==
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:65333
| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Thanks, CT. The section on DataView in Chapter 8 of
| ado.net core reference will be some going. vb.net has
| lost much of it's rad features, I'm afraid. It seems to
| me I'll have to clear the dataset and refill it. Am I
| right?
|
| dennist
|
 
S

Severin

Dim dr as Datarow
Dim iRow as Integer

iRow = DataSet.Tables(0).Rows.Count - 1
dr = DataSet.Tables(0).Rows(iRow)

You now have access to all fields in the last row through the DataRow object
(dr)
 
G

Guest

David, I can't find access to the value of the field.
whether I use dr(0) or dr("ID") the only choice after the
dot is GetType, and after that nothing seems to represent
the value. I would appreciate your illuminating me.
This is important to me, to create the class library I
want that suites the tables I design.

thank you.

dennist
 
G

Guest

Kevin, thank you for helping me as always. The dataview
will almost do what I want, and if necessary I would
resort to it. But David's method, if I could figure out
how to grab the column value, rather than just about
every other piece of information about the column, would
give me pure navigation capabilities by code.

dennist
 
K

Kevin Yu [MSFT]

Hi DennisT,

I think David's method should work. Please try to check if you have
reference to the correct table and if the table has column in it. You can
bound the result DataSet to a datagrid to do it.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
--------------------
| Content-Class: urn:content-classes:message
| From: <[email protected]>
| Sender: <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
| Subject: RE: how to position to a row in a table
| Date: Wed, 5 Nov 2003 02:28:12 -0800
| Lines: 60
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOjh4O9ftAFQbSWT/KoFN0+jJH2Sw==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:65473
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Kevin, thank you for helping me as always. The dataview
| will almost do what I want, and if necessary I would
| resort to it. But David's method, if I could figure out
| how to grab the column value, rather than just about
| every other piece of information about the column, would
| give me pure navigation capabilities by code.
|
| dennist
|
|
| >-----Original Message-----
| >Hi Dennist,
| >
| >You needn't refill the dataset. You can create another
| DataView from the
| >DataTable by calling the constructor of DataView, and
| get the last record.
| >
| >Kevin Yu
| >=======
| >"This posting is provided "AS IS" with no warranties,
| and confers no
| >rights."
| >
| >--------------------
| >| Content-Class: urn:content-classes:message
| >| From: <[email protected]>
| >| Sender: <[email protected]>
| >| References: <[email protected]>
| >| Subject: how to position to a row in a table
| >| Date: Tue, 4 Nov 2003 02:38:30 -0800
| >| Lines: 7
| >| Message-ID: <[email protected]>
| >| MIME-Version: 1.0
| >| Content-Type: text/plain;
| >| charset="iso-8859-1"
| >| Content-Transfer-Encoding: 7bit
| >| X-Newsreader: Microsoft CDO for Windows 2000
| >| X-MimeOLE: Produced By Microsoft MimeOLE
| V5.50.4910.0300
| >| Thread-Index: AcOiv8m11ZdPAEukTOSNSiutxk9slA==
| >| Newsgroups: microsoft.public.dotnet.framework.adonet
| >| Path: cpmsftngxa06.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.framework.adonet:65333
| >| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| >| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
| >|
| >| Thanks, CT. The section on DataView in Chapter 8 of
| >| ado.net core reference will be some going. vb.net has
| >| lost much of it's rad features, I'm afraid. It seems
| to
| >| me I'll have to clear the dataset and refill it. Am I
| >| right?
| >|
| >| dennist
| >|
| >
| >.
| >
|
 
K

keyur shah

Quite a interesting situation... use dataview to resolve ur issue...
makes sense... i read in some book and even some article long back ...
hope this info help.s

Keyur Shah
Verizon Communications
732-423-0745
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top