C# 使用SQLite

C# 使用SQLite

操作SQLite跟MSSQL一樣

只是要USING正確的SQLite DLL

我是用VS STUDIO的NUGET

直接下載就好

範例CODE如下:

string path = @"d:\SQLite database.db";
SQLiteConnection = new SQLiteConnection("data source=" + path);
SQLiteConnection.Open();

StringBuilder sbSql = new StringBuilder();
SQLiteCommand cmd = SQLiteConnection.CreateCommand();

sbSql.Clear();
sbSql.AppendFormat(@"  
                    SELECT *
                    FROM table
                    ";

cmd.CommandText = sbSql.ToString();

SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
DataTable table = new DataTable();
adapter.Fill(table);

if(table.Rows.Count>0)
{
          //code
}

else
{
                       
}

SQLiteConnection.Close();

 

 

自我LV~