MoveFirst, MoveLast

M

Marcin Zmyslowski

Hello!

I use data.read and data.getValue(Id_column) to get the value of
specified column. Unfortunately there are some differences between
VBScript and Visual Basic (MS Access) and I cannot move to the first and
last record of data. I searched archieves and I couldn`t find any
example how to do it. I use MS SQL Server 2000 as a server and I wrote a
sql query where I used data.reader. Could you give me the example how to
modify the code to have movefirst and movelast possibilites?

Thank you in advance
Marcin
 
C

Cathal Connolly [VB MVP]

you can't use a datareader to do that, as it's a forward only data
construct. If you wish to navigate, use the dataset. You'll need to give it
a dataview, and then do a check on the rows, and read the individual row i.e


Dim cnNorthwind As SqlConnection = new SqlConnection("Persist
Security Info=False;Integrated
Security=SSPI;database=northwind;server=mySQLServer")
' Create a SqlDataAdapter for the Suppliers table.
Dim adpSuppliers As SqlDataAdapter = new SqlDataAdapter()
' A table mapping tells the adapter what to call the table.
adpSuppliers.TableMappings.Add("Table", "Suppliers")
cnNorthwind.Open()
Dim cmdSuppliers As SqlCommand = _
new SqlCommand("SELECT * FROM Suppliers", cnNorthwind)
cmdSuppliers.CommandType = CommandType.Text

adpSuppliers.SelectCommand = cmdSuppliers

ds = New DataSet("Customers")
adpSuppliers.Fill(ds)
dim myDataview as dataview=new dataview(ds.tables("suppliers"))
'optionally use mydataview.sort to sort i.e. mydataview.sort="supplierID"
dim intLast as integer=myDataView.count-1
'movelast
console.write (myDataView(intLast)("somecolumn").tostring
'movefirst
console.write (myDataView(0)("somecolumn").tostring

Hello!

I use data.read and data.getValue(Id_column) to get the value of
specified column. Unfortunately there are some differences between
VBScript and Visual Basic (MS Access) and I cannot move to the first and
last record of data. I searched archieves and I couldn`t find any
example how to do it. I use MS SQL Server 2000 as a server and I wrote a
sql query where I used data.reader. Could you give me the example how to
modify the code to have movefirst and movelast possibilites?

Thank you in advance
Marcin
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top