Click here to Skip to main content
15,885,365 members
Articles / Programming Languages / Visual Basic

ADO.NET RecordSet Library

Rate me:
Please Sign up or sign in to vote.
4.44/5 (15 votes)
18 Jul 2006CPOL6 min read 168.8K   2K   40  
An ADO.NET recordset class.
Module Module1

    Dim rs As ADO_NET_RecordSet_Library.RecordSet

    Sub Main()

        rs = New ADO_NET_RecordSet_Library.RecordSet
        If Not rs.Connection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb") Then
            Console.WriteLine("Error while trying to connect to the database")
            Exit Sub
        End If
        If Not rs.OpenRecordSet("SELECT * FROM Persons") Then
            Console.WriteLine("Error while trying to open the recordset")
            Exit Sub
        End If

        'run the list
        Console.WriteLine("The database has these {0} persons", rs.RecordsCount)
        Do Until rs.EOF
            Console.WriteLine("ID: " & rs.FieldValue(0) & " Name: " & rs.FieldValue(1) & " Surname: " & rs.FieldValue(2))
            rs.MoveNext()
        Loop
        Console.WriteLine()

        'add a name
        Console.WriteLine("Adding Joaquim Almeida")
        rs.AddNew()
        rs.FieldValue(1) = "Joaquim"
        rs.FieldValue(2) = "Almeida"
        rs.Update()
        Console.WriteLine()
        'run the list
        Console.WriteLine("The database has these persons")
        Do Until rs.EOF
            Console.WriteLine("ID: " & rs.FieldValue(0) & " Name: " & rs.FieldValue(1) & " Surname: " & rs.FieldValue(2))
            rs.MoveNext()
        Loop
        Console.WriteLine("The database now has these {0} persons", rs.RecordsCount)

        rs.FindFirst("Surname", "Smith")
        Console.WriteLine("Found {0} persons with the Surname 'Smith'", rs.RecordsFound)
        Do Until rs.NoMatch
            Console.WriteLine("ID: " & rs.FieldValue(0) & " Name: " & rs.FieldValue(1) & " Surname: " & rs.FieldValue(2))
            rs.FindNext("Surname", "Smith")
        Loop

    End Sub

End Module

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Portugal Portugal
I'm that guy that falls for the impossible...

Comments and Discussions