Determine total records and move next and previous

victor64

Well-known member
Joined
Nov 9, 2008
Messages
60
Programming Experience
Beginner
Hello,

How do I determine the total number of records founds?, I would also like to add to two buttons to move to the next or previous records, what code should I add in those button?

Thanks,

Victor

Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\aopt2002orgorg.mdb;Persist Security Info=True;Jet OLEDBatabase Password=testaopupdate"
Dim objConnection As New OleDb.OleDbConnection(ConnectionString)

'data adapter
Dim objDataAdapter As New OleDb.OleDbDataAdapter(mySQL_Statement, objConnection)

'dataset object
Dim objDataSet As New DataSet
'fill dataset
objConnection.Open()
?
?
?
objDataAdapter.Fill(objDataSet, "SN")
objConnection.Close()
 
To get total number of records found
1. From database: Use a select statement that counts total number of records from a given table using a particular column. eg SELECT count(columnName) FROM TABLENAME.
2. From Program Code: After ur select statement, try to fill ur retrieved records from dataAdapter to a datatable object. eg
Dim x as integer
MyDataAdapter.Fill (MyDataTable)
x= MyDataTable.Rows.Count

To Move Next between records(try dis code at the buttom click event)
Dim x as Integer
x= x+1
If not MyDataTable.Rows.count =0 then
If x > MyDataTable.Rows.Count -1 then
x= MyDataTable.Rows.Count -1
else
Exit sub
end if
txt.Text= MyDataTable.Rows(x).Item([Specify Column])
End If


To Move Previous between records (Do the opposite of above)
I hope this helps u.
 
Back
Top