Database query VB.Net Exercise - Visual Basic Programming Course


Database query


Create a program to display the data about books which your previous program has stored.


Imports System
Imports System.Data.SQLite
Namespace ReadSQL
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim conexion As SQLiteConnection = New SQLiteConnection("Data Source=ejemplo01.sqlite;" & " Version=3; New=False; Compress=True;")
            Dim consulta As String = "select * from books"
            Dim cmd As SQLiteCommand = New SQLiteCommand(consulta, conexion)
            Dim datos As SQLiteDataReader = cmd.ExecuteReader()

            While datos.Read()
                Dim name As String = Convert.ToString(datos(0))
                Dim autor As String = Convert.ToString(datos(1))
                Dim genre As String = Convert.ToString(datos(2))
                Dim summary As String = Convert.ToString(datos(3))
                System.Console.WriteLine("Name: {0}," & " Autor: {1}, Genre: {2}, Summary: {3}", name, autor, genre, summary)
            End While

        End Sub
    End Class
End Namespace

Juan A. Ripoll - Systems Tutorials and Programming Courses © 2024 All rights reserved.  Legal Conditions.