Solved

ADO.NET Record navigation

Posted on 2004-04-06
5
608 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now