将 .NET 日期时间转换为 SQLite 日期时间
问题描述:
我尝试在 C# 中使用日期时间进行查询,数据库:SQlite.
I've tried to query with a datetime in C#, database : SQlite.
cmd.CommandText = @"select * from PhieuNhap where NgayNhap=$NgayNhap";
cmd.Parameters.Add(new SQLiteParameter("$NgayNhap", SqlDbType.DateTime).Value = ngayNhap;
ngayNhap 是 DateTime 类型.
ngayNhap is a DateTime type.
但这种方式似乎行不通.
But it seems doesn't work this way .
答
您是否收到异常或值被忽略了?
Do you get an exception or is the value just ignored?
您可以尝试的一件事是不要手动设置参数类型:
One thing you could try is not setting the parameter type manually:
cmd.CommandText = @"select * from PhieuNhap where NgayNhap=$NgayNhap";
cmd.Parameters.Add(new SQLiteParameter("$NgayNhap", ngayNhap));