Solved

ADO.NET Record navigation

Posted on 2004-04-06
5
612 Views
Last Modified: 2008-03-17
       

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
Comment
Question by:robbe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10770769
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
 
LVL 8

Expert Comment

by:gregasm
ID: 10771007
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
 
LVL 6

Author Comment

by:robbe
ID: 10772216
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
 
LVL 7

Expert Comment

by:ScrptMasta
ID: 10775356
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
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 125 total points
ID: 10775705
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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question