Database query Learn programming Visual Basic (VB.net)

Lesson:

Access To Relational Databases


Exercise:

Database query 45


Objetive:

Create a program to display the data about books which your previous prorgram 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