سلام
هیچ فرقی با دستورات و واکشی های SqlServer نداره، این کلاس DALBase منه میتونی از این استفاده کنی
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Finisar.SQLite;
using System.IO;
namespace DAL
{
public class DALBase
{
private SQLiteDataAdapter sda;
private DataSet ds = new DataSet();
private DataTable dt = new DataTable();
public static string ConnectionStringSQLite
{
get
{
return "Data Source=Database//SiteList.db;Version=3;New=False;Compress=True;";
}
}
public int ExecuteNoneQuery(CommandType commandType, string commandText)
{
using (SQLiteConnection con = new SQLiteConnection(ConnectionStringSQLite))
{
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = con;
cmd.CommandType = commandType;
cmd.CommandText = commandText;
con.Open();
int retVal = cmd.ExecuteNonQuery();
con.Close();
return retVal;
}
}
public int ExecuteNoneQuery(CommandType commandType, string commandText, params SQLiteParameter[] commandParameters)
{
using (SQLiteConnection con = new SQLiteConnection(ConnectionStringSQLite))
{
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = con;
cmd.CommandType = commandType;
cmd.CommandText = commandText;
foreach (SQLiteParameter s in commandParameters)
cmd.Parameters.Add(s);
con.Open();
int retVal = cmd.ExecuteNonQuery();
con.Close();
return retVal;
}
}
public object ExecuteScaler(CommandType commandType, string commandText)
{
using (SQLiteConnection con = new SQLiteConnection(ConnectionStringSQLite))
{
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = con;
cmd.CommandType = commandType;
cmd.CommandText = commandText;
con.Open();
object retVal = cmd.ExecuteScalar();
con.Close();
return retVal;
}
}
public SQLiteDataReader ExecuteReader(CommandType commandType, string commandText, SQLiteParameter[] commandParameters)
{
using (SQLiteConnection con = new SQLiteConnection(ConnectionStringSQLite))
{
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = con;
cmd.CommandType = commandType;
cmd.CommandText = commandText;
cmd.Parameters.Add(commandParameters);
foreach (SQLiteParameter sq in commandParameters)
cmd.Parameters.Add(sq);
bool mustCloseConnection = false;
try
{
if (con.State != ConnectionState.Open)
{
mustCloseConnection = true;
con.Open();
}
else
{
mustCloseConnection = false;
}
SQLiteDataReader dataReader;
dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
return dataReader;
}
catch
{
if (mustCloseConnection)
con.Close();
throw;
}
}
}
public DataTable ExecuteDatatable(CommandType commandType, string commandText)
{
using (SQLiteConnection con = new SQLiteConnection(ConnectionStringSQLite))
{
DataTable dt = new DataTable();
try
{
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = con;
cmd.CommandType = commandType;
cmd.CommandText = commandText;
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
con.Open();
da.Fill(dt);
con.Close();
}
catch { }
return dt;
}
}
}
}