Reputation: 1055
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
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
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()
Upvotes: 3