轻量级数据库SQLite ,用于小型的工具软件使用。
这文主要就是介绍 DB Browser for SQLite 如何快速完成一个小程序的增删改查。
SQLite Expert Professional是一款可视化的数据库管理工具,允许用户在 SQLite 服务器上执行创建、编辑、复制、提取等操作。SQLite Expert支持所有的图形界面的SQLite特征。它包括一个可视化查询生成器,一个SQL编辑与语法突出和代码自动完成,强大的table和view设计与导入导出功能。 SQLite Expert现在分为两个版本,一个是免费的Personal Edition,一个是收费 Professional Edition。 |
public class Mylocal
{
string conString = string.Format(@"Data Source={0}; Pooling=false; FailIfMissing=false;", System.Windows.Forms.Application.StartupPath + @"\test.db");
public void LogHistory(string bucketId, string fileId, string remarkName)
{
if (IsExistedTypeTable())
{
try
{
using (var dbConn = new System.Data.SQLite.SQLiteConnection(conString))
{
dbConn.Open();
using (System.Data.Common.DbCommand cmd = dbConn.CreateCommand())
{
cmd.CommandText = @"INSERT INTO TypeRecords (BucketID,FileID,TypeName,UserName) VALUES(@bucketid,@fileid,@typename,@username)";
var p1 = cmd.CreateParameter();
p1.ParameterName = "@bucketid";
p1.Value = bucketId;
var p2 = cmd.CreateParameter();
p2.ParameterName = "@fileid";
p2.Value = fileId;
//typename, username
var p3 = cmd.CreateParameter();
p3.ParameterName = "@typename";
p3.Value = remarkName;
var p4 = cmd.CreateParameter();
p4.ParameterName = "@username";
p4.Value = BaseBll.CrtUser;
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add(p3);
cmd.Parameters.Add(p4);
cmd.ExecuteNonQuery();
cmd.Dispose();
}
if (dbConn.State != System.Data.ConnectionState.Closed) dbConn.Close();
dbConn.Dispose();
}
}
catch
{
logger.Debug("写入操作记录时异常");
}
}
}//LogHistory
public string GetMarkNameBy(string BucketId, string FileId)//原逻辑的GetMarkBy接口
{
try
{
using (var dbConn = new System.Data.SQLite.SQLiteConnection(conString))
{
dbConn.Open();
using (System.Data.Common.DbCommand cmd = dbConn.CreateCommand())
{
//cmd.CommandText = @"INSERT INTO TypeRecords (BucketID,FileID,TypeName,UserName) VALUES(@bucketid,@fileid,@typename,@username)";
//read from the table
cmd.CommandText = @"SELECT TypeName FROM TypeRecords WHERE BucketID=@bucketid AND FileID=@fileid AND UserName = @username limit 1 ";
var p1 = cmd.CreateParameter();
p1.ParameterName = "@bucketid";
p1.Value = BucketId;
var p2 = cmd.CreateParameter();
p2.ParameterName = "@fileid";
p2.Value = FileId;
var p3 = cmd.CreateParameter();
p3.ParameterName = "@username";
p3.Value = BaseBll.CrtUser;
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add(p3);
using (System.Data.Common.DbDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
//long id = reader.GetInt64(0);
string TypeInfo = reader.GetString(0);
return TypeInfo;
}
}
cmd.Dispose();
}
if (dbConn.State != System.Data.ConnectionState.Closed) dbConn.Close();
dbConn.Dispose();
}
}
catch
{
logger.Debug("获取历史操作记录数据时异常");
}
return "";
}
}