tags:

views:

3230

answers:

5

I've done this before in C++ by including sqlite.h but is there a similarly easy way in C#?

+3  A: 

There is a list of Sqlite wrappers for .Net at http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers. From what I've heard http://sqlite.phxsoftware.com/ is quite good. This particular one lets you access Sqlite through ADO.Net just like any other database.

robintw
+15  A: 

ADO.NET 2.0 Provider for SQLite have over 200 downloads every day, so I think you are safe using that one.

Espo
+6  A: 

I've used this with great success:

http://sqlite.phxsoftware.com/

Free with no restrictions.

--Bruce

bvanderw
Just for consistency, because people is talking about both as different things. In "sqlite.phxsoftware.com" you are pointed to "sourceforge.net/projects/sqlite-dotnet2" for downloading.
yeyeyerman
+1  A: 

There's also now this option: http://code.google.com/p/csharp-sqlite/ - a complete port of SQLite to C#.

xanadont
+6  A: 

I'm with, Bruce. I AM using http://sqlite.phxsoftware.com/ with great success as well. Here's a simple class example that I created:

using System;
using System.Text;
using System.Data;
using System.Data.SQLite;

namespace MySqlLite
{
      class DataClass
      {
        private SQLiteConnection sqlite;

        public DataClass()
        {
              //This part killed me in the beginning.  I was specifying "DataSource"
              //instead of "Data Source"
              sqlite = new SQLiteConnection("Data Source=/path/to/file.db");

        }

        public DataTable selectQuery(string query)
        {
              SQLiteDataAdapter ad;
              DataTable dt = new DataTable();

              try
              {
                    SQLiteCommand cmd;
                    sqlite.Open();  //Initiate connection to the db
                    cmd = sqlite.CreateCommand();
                    cmd.CommandText = query;  //set the passed query
                    ad = new SQLiteDataAdapter(cmd);
                    ad.Fill(dt); //fill the datasource
              }
              catch(SQLiteException ex)
              {
                    //Add your exception code here.
              }
              sqlite.Close();
              return dt;
  }

}

DA