Home > .NET > SQLite in .Net

SQLite in .Net

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:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: