?
Solved

ADO.NET Record navigation

Posted on 2004-04-06
5
Medium Priority
?
613 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 375 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

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…
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:…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

801 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