Wednesday, July 11, 2012

c# - Reading/Selecting data from SQLite database

Below is the code to read data from SQL Lite databases.These are extensively used in IPhone as backup files.

You need to download the following dll System.Data.SQLite.dll and reference that in your project.The dll can be found here


http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki


using System.Data.SQLite;


using (SQLiteConnection oSqlLiteConnection = new SQLiteConnection("Data Source=" + sFilePath))

{
     oSqlLiteConnection.Open();
     SQLiteCommand cmd = new SQLiteCommand("Select * from Scalars", oSqlLiteConnection);
     SQLiteDataReader dr = cmd.ExecuteReader();

     while (dr.Read())

         Console.WriteLine(String.Format("{0}\t{1}\t{2}\t{3}", dr.GetValue(0), dr.GetValue(1), dr.GetValue(2)));
}

2 comments:

Unknown said...

Just what I need. Simple and excellent article!!

Unknown said...

Exactly what I needed. Simple and excellent article!!