Database query VB.Net Exercise - Visual Basic Programming Course


 Exercise

Database query

Objetive

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

Code

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;")
            conexion.Open()
            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

            conexion.Close()
        End Sub
    End Class
End Namespace


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