How to work with SQLLite Database Using Asp.net


Today, we will discuss how to establish a Connection with SqlLite Database using Asp.net. In this Article we will know what are the Namespaces should we we used to get SQLiteConnection and SQLiteDataAdapter Class ? How to establish a Connection with SQL-lite Database using asp.net ? How to write a inline query in asp.net for SqlLite Database ?

There are Many Databases like SQl-server, Oracle , My-sql Database to store and retrieve the data using ADO.net but how to connect with SQLLITE database in asp.net . This database almost resembles like SQL-SERVER.

But in .Net Framework there is no predefined namespace that exists to connect with the SQLite Database. we need to add a reference SQLite.NET.dll in your project . which you will find by Googling it. or please refer for the Following site
https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

if you want work with SQllite Linq than you need to download System.Data.SQLite.Linq.dll and add reference in your Project.

After successfully adding a reference in your .Net than you need to get Connection class the following statement you need to write for that.


SQLiteConnection objcon = new SQLiteConnection("your Connection string here" );


the Connection string as follows for ex:-

sqlite_conn = new SQLiteConnection("Data Source=C:\SQLITEDATABASES\SQLITEDB1.sqlite;Version=3;");

OR

sql_con = new SQLiteConnection("Data Source=Tlist.db;Version=3;New=False;Compress=True;");

after Writing the Connection statement we need to write SqlliteCommand than it follows like this


SQLiteCommand cmd =new SQLiteCommand(query, sql_con);


Now after writing the Cmd we need to know the state of the Connection whether it is Opened or Closed for that you need to write the below statement

if(sql_con.State == system.Data.Connection.Open)
{
sql_con.Close();
}
if(sql_con.State == system.Data.Connection..Close)
{
sql_con.Open();
}


then the Command ExecuteQuery OR Execute scalar is as similar with sqlServer statement goes like this


object stepid = sqlCmd.ExecuteScalar();


but you want use Dataadapter than sqlDataAdapter will not work than you need to have SQLiteDataAdapter Look the below code


SQLiteDataAdapter sqladapt = new SQLiteDataAdapter(COMMAND,CON)
sqladapt.Fill(dst);


Article by srirama
A Good advice from parent to a Child , Master to a Student , Scholar to an Ignorant is like a doctor prescribed pill it is bitter to take but when they take it will do all good for them --- Bhushan

Follow srirama or read 74 articles authored by srirama

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: