SpongeBob SquarePants
SpongeBob SquarePants

Reputation: 1055

How to create database and add 2 table in SQLite

I am using SQLite ADO.NET Provider.

I want to create a database with 2 tables via code in vb.net .

Please provide code for the same.

I am using VS 2010 Winforms, working under XP SP3 Pro

Upvotes: 3

Views: 16972

Answers (2)

user2866752
user2866752

Reputation: 80

For those who need this, here is an updated working code...

SQLiteConnection.CreateFile("c:\mydatabasefile.db3")
Using Query As New SQLiteCommand()
    Connection.ConnectionString ="DataSource=c:\mydatabasefile.db3;Version=3;New=False;Compress=True;"
    Connection.Open()
        With Query 
            .Connection = Connection
            .CommandText = "CREATE TABLE MyTable(CustomerID INTEGER PRIMARY KEY ASC, FirstName VARCHAR(25))"
        End With
Query.ExecuteNonQuery()
Connection.Close()
End Using

Upvotes: 1

p.campbell
p.campbell

Reputation: 100557

Use the SQLiteConnection's CreateFile() method.

SQLiteConnection.CreateFile("c:\\mydatabasefile.db3")

More info on the System.Data.SQLite forums

You can then send ad-hoc CREATE TABLE statements to the engine:

dim myTableCreate as String = 
                    "CREATE TABLE MyTable(CustomerID INTEGER PRIMARY KEY ASC, 
                     FirstName VARCHAR(25));"

cmd.CommandText = myTableCreate
cmd.ExecuteNonQuery()

More on SQLite CREATE TABLE.

Upvotes: 3

Related Questions