If you are into developing portable apps and considers using databases then you might already heard of the most widely deployed SQL database engine (as they claim) called SQLite. If you still don't know, SQLite is an open source software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. It implements most of the SQL-92 standard including triggers, views, and etc but it doesn't support stored procedures.To start your C# + SQLite project, follow these easy steps.
1. Download ADO.NET 2.0 Provider for SQLite.
2. Create your C# Project and Copy the DLL (System.Data.SQLite.DLL) to your project then add a reference to it.
3. Since SQLite doesn't come with a GUI administration then you might want to download free SQLite GUI clients like SQLite Administrator.
4. You can start creating your database using your downloaded SQLite GUI Client.

5. If your database is already setup, include the following namespaces on the Using directive.
using System.Data;
using System.Data.SQLite;
6. Insert the following C# code on your project to connect to your newly created SQLite database.
public void ConnectToSQLite ()
{
SQLiteConnection cn= new SQLiteConnection();
try
{
cn.ConnectionString = "Data Source=C:test.s3db";
cn.Open();
//perform query, update, insert, delete (to be discuss on the related tutorial)
}
catch {
//display any exeptions
}
finally {
cn.Close();
}
}
Now if your connection string is correct, you should be able to connect to SQLite database successfully.
To stay up-to-date on Technology news, subscribe now.
0 comments:
Post a Comment