Archive

Archive for the ‘.NET’ Category

SQLite in .Net

June 25, 2012 Leave a comment

SQLite with .Net

Steps

1. Download and Install ADO.NET 2.0 Provider for SQLite from here http://sourceforge.net/projects/sqlite-dotnet2/

2. Create a website using Visual studio 2010

3. Add a reference to dll file C:\Program Files (x86)\SQLite.NET\bin\System.Data.SQLite.dll

4. Use Server Explorer to connect a SQLite database. Click Connect to database from Server Explorer. Select SQLite Database file -> Continue -> New -> type database filename -> Save -> OK

5. Check the connection string of newly created SQLite database from Server explorer

6.  Sample code

using System.Data.SQLite;

SQLiteConnection  conn = newSQLiteConnection();

conn.ConnectionString =@”data source=C:\Users\uerid\Documents\testdb.db”;

conn.Open();

SQLiteCommand command = conn.CreateCommand();

command.CommandText =“CREATE TABLE Test (id integer primary key AUTOINCREMENT, text varchar(100))”;

command.ExecuteNonQuery();

command = conn.CreateCommand();

command.CommandText =“INSERT INTO Test (text) VALUES (@1)”;

SQLiteParameter parameter = command.CreateParameter();

parameter.ParameterName =“@1”;

parameter.Value =“some text”;

command.Parameters.Add(parameter);

command.ExecuteNonQuery();

Advertisements
Categories: .NET Tags: