C# SQLite数据库入门使用说明

2020-01-05 10:02:20王冬梅


//存在更新,不存在插入
string updateSql = "REPLACE INTO serverinfo(Name,Url,DelayTime,UsageCounter, Status,CreateTime) VALUES(@Name,@Url,@DelayTime,@UsageCounter,@Status, @CreateTime)";
Dictionary<string, object> ups = new Dictionary<string, object>();
ups.Add("Name", name);
ups.Add("Url", url);
ups.Add("DelayTime", delayTime);
ups.Add("UsageCounter", usageCounter);
ups.Add("Status", status);
ups.Add("CreateTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
int count= SqliteHelper.ExecuteNonQuery(connStr, updateSql, ups);
if (count>0)
{
 return true;
}
else
{
 return false;
}

5. 删除


//删除记录
string updateSql =
 "DELETE FROM serverinfo where content=@Content and flag=@Flag;";
Dictionary<string, object> updateParameters = new Dictionary<string, object>();
updateParameters.Add("Content", Content);
updateParameters.Add("Flag", Flag);
int count = SqliteHelper.ExecuteNonQuery(connStr, updateSql, updateParameters);
if (count > 0)
{
 return true;
}
else
{
 return false;
}

四、参考文章

  • Create SQLite Database and table
  • Writing to a SQLite Database in C#
  • SQLite with VS2012 and .NET 4.5 — ANY CPU Build
  • how to check if a table exists in C#
  • SQLite auto increment issue
  • Inserting a date to SQLite
  • SQLite REPLACE Statement
  • sqlite select with condition on date
  • Using SQLite how do I index columns in a CREATE TABLE statement?

    总结

    以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对ASPKU的支持。