Quick introduction to SQLite with C#
By Anuraj P on February 22nd, 2011 . No Comments .
Recently I am started working with SQLite Database. You can find more information about SQLite Database from the website (http://www.sqlite.org/).
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain. – From SQLite website.
You can download the System.Data.Sqlite from system.data.sqlite.org website.
Here is a sample code snippet which connects to a SQLite DB and prints all the objects in the SQLite database.
string dbName = @"C:\Sample.db3";
using (SQLiteConnection sqlConnection =
new SQLiteConnection("Data Source=" + dbName + ";Version=3;New=True;Compress=True;"))
{
using (SQLiteCommand sqlCommand = sqlConnection.CreateCommand())
{
sqlConnection.Open();
sqlCommand.CommandText = "SELECT * FROM sqlite_master";
using (SQLiteDataReader dataReader =
sqlCommand.ExecuteReader(CommandBehavior.CloseConnection))
{
Console.WriteLine("Name : Type");
while (dataReader.Read())
{
Console.WriteLine(
dataReader["Name"].ToString() + ":" + dataReader["Type"].ToString());
}
}
}
}
Don’t forgot to Add reference of System.Data.SQLite.dll in the project.
No Responses to “Quick introduction to SQLite with C#”
RSS feed for comments on this post. TrackBack URL