• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 615
  • Last Modified:

ADO.NET Record navigation

       

Hi,

I'm making a program and i need to navigate forward and backward trough records. I was used to work with the original ADODB commands like RS.movenext,... Now i need to do this in VB.NET but have no idea how to do this. I'm programming in VB.NET and i want to use an SQL query to get the records. After that the user can browse the records by using a back and next button. Can somebody give me a simple, clear and documentated VB.NET example how to do this.

Thanks in advance
Robbe

My code so far:

Try
            Dim cmd As New System.Data.SqlClient.SqlCommand("Select FuifID,Fuifnaam,Fuifstart,Actief FROM tblFuif WHERE actief=1", SQLConn)
            Dim reader As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader()
            While reader.Read()

            End While
            reader.Close()
Catch ex As Exception
            MsgBox("Error while fetching tblPersoon: " & ex.Message, MsgBoxStyle.Critical)
End Try
0
robbe
Asked:
robbe
1 Solution
 
Arthur_WoodCommented:
DO NOT use a DataReader.  DataReaders are FORWARD ONLY , READ ONLY objects, so you cannot move backwards.

What you want to use is a DataSet object in combination with a DataAdapter.

I do not have .NET installed on this PC, so I can't give you the complete command sequence, but look up DataSet and DataAdapter in the Help system.

AW

0
 
gregasmCommented:
You must use the binding context object.

That way you can set the position of the records.


look here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsbindingcontextclassctortopic.asp
0
 
robbeAuthor Commented:
And how do i use the dataobject with an sql query ? becouse in the MS example it is used with a groupbox and 2 textboxs
0
 
ScrptMastaCommented:
See if any of these may help with the transition from ADO to ADO.NET.

ADO.NET for the ADO Programmer
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/adonetprogmsdn.asp

Some Code Examples
Microsoft® ADO.NET (Core Reference): Sample Code
http://www.microsoft.com/downloads/details.aspx?familyid=bae2de67-0062-4bf5-b120-f970865be92e&displaylang=en

0
 
Arthur_WoodCommented:
Dim cn as SqlConnection
Dim cmm as SqlCommand
Dim da as SqlDataAdapter
Dim ds as DataSet
Dim dr as DataRow
Dim RowNumber as Integer = 0

cn = new SqlConnection(<YourConnectionString>)
cn.Open()

cmm = New SqlCommand("Select FuifID,Fuifnaam,Fuifstart,Actief FROM tblFuif WHERE actief=1", cn)
da = New SqlDataAdapter(cmm)

da.Fill(ds)
" a DataSet is made up of One or More 'Tables", and each Table is made up of 1 or More Rows)
dr = ds.Tables(0).Rows(RowNumber) 'first Row in the First (and only) Table in this DataSet  

'to navigate through the Table, one row at a time, simply increment (to move forward) or decrement(to move backward) the RowNumber.  You will need to check each time if RowNumber = 0 - First Record, or RowNumber = Tables(0).Row.Count  - Last Record


That is how you do it in the ADO.NET world.

AW
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Tackle projects and never again get stuck behind a technical roadblock.
Join Now