Ejercicio
Consulta base de datos
Objetivo
Cree un programa para mostrar los datos sobre los libros que su programa anterior ha almacenado.
Código
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