Solved

ADO.NET Record navigation

Posted on 2004-04-06
5
611 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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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 …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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