我正在使用WPF/C#&编写一个小应用程序SQLITE。
其中一个函数将包含两个日期/时间值的记录插入到table.
我想知道是否有适当的方法来执行此操作(以确保日期/月份字段的存储一致)。
我创建了一个INSERT使用参数和日期变量的查询 (clsVariables.DatActivityEnd = DateTime.Now;)。
String cntnStr = ClsVariables.StrDb;
var connection = new SQLiteConnection(cntnStr);
connection.Open();
using (SQLiteCommand cmd = connection.CreateCommand())
{
cmd.CommandText =
"INSERT INTO tblActivity ([Activity_Category], [Activity_Category_Sub], [Activity_Start], [Activity_End], [Activity_Duration]) VALUES (@ActivityCategory, @ActivityCategorySub, @ActivityStart, @ActivityEnd, @ActivityDuration);";
cmd.Parameters.Add(new SQLiteParameter("@ActivityCategory", ClsVariables.StrActivityCurrent));
cmd.Parameters.Add(new SQLiteParameter("@ActivityCategorySub", ClsVariables.StrActivitySubCurrent));
cmd.Parameters.Add(new SQLiteParameter("@ActivityStart", ClsVariables.DatActivityStart.ToString()));
cmd.Parameters.Add(new SQLiteParameter("@ActivityEnd", ClsVariables.DatActivityEnd.ToString()));
cmd.Parameters.Add(new SQLiteParameter("@ActivityDuration", ClsVariables.DblActivityDuration));
cmd.ExecuteNonQuery();
}
connection.Close();
Run Code Online (Sandbox Code Playgroud)
还有什么我应该做的吗 - 谢谢?
我是C#/ WPF / SQLite的新手,并且创建了一个表单,该表单需要显示多个计算(来自两个不同的表)。我想知道你们认为最快的方法是(如果有人可以提供代码的粗略指南,那将是很大的帮助)。
这有点粗糙(并且不能完全正常工作),但是这里是:
string cs = ClsVariables.StrDb;
using(SQLiteConnection con = new SQLiteConnection(cs))
{
con.Open();
string stm = "SELECT [ID] FROM tblActivities WHERE [Activity]='Sleeping'";
using (SQLiteCommand cmd = new SQLiteCommand(stm, con))
{
//I'm guessing this is where I need count the number of rows (but haven't figure that bit out just yet
}
con.Close();
}
Run Code Online (Sandbox Code Playgroud)