Database creation Learn programming Visual Basic (


Access To Relational Databases


Database creation


Create a program to ask the user for data about books (title, author, genre, and summary) and store them in a SQLite database.


Imports System
Imports System.Data.SQLite
Imports System.IO
Public Class DatabaseCreation
    Private Shared Sub Main(ByVal args As String())
        Dim conexion As SQLiteConnection
        Dim cmd As SQLiteCommand

            conexion = New SQLiteConnection("Data Source=ejemplo01.sqlite;Version=3;" & " New=True; Compress=True;")

            If Not File.Exists("ejemplo01.sqlite") Then
                Dim creacion As String = "create table books (" & " title varchar(50), autor varchar(50)," & " genre varchar(50), summary varchar(50))"
                cmd = New SQLiteCommand(creacion, conexion)
            End If

            Dim line As String
            Dim title As String = "", autor As String = "", genre As String = "", summary As String = ""

                Console.Write("Title: ")
                line = Console.ReadLine()
                If line IsNot Nothing Then title = line
                Console.Write("Autor: ")
                line = Console.ReadLine()
                If line IsNot Nothing Then autor = line
                Console.Write("Genre: ")
                line = Console.ReadLine()
                If line IsNot Nothing Then genre = line
                Console.Write("Summary: ")
                line = Console.ReadLine()
                If line IsNot Nothing Then summary = line
                Dim insercion As String = "insert into books values ('" & title & "', '" & autor & "','" & genre & "', '" & summary & "')"
                cmd = New SQLiteCommand(insercion, conexion)
                Console.WriteLine("Insert OK!")
            Loop While line IsNot Nothing

        Catch e As Exception
            Console.WriteLine("Error" & e.Message)
        End Try
    End Sub
End Class

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