【发布时间】:2022-01-12 23:32:06
【问题描述】:
我想在我的项目倒计时到期列中添加。我已经创建了医学数据库。
我正在为药物过期倒计时而苦苦挣扎,但它没有显示正确的过期天数。最后一栏。我在图片上展示了它:
我的过期日期功能:
public void UpdateCountdown()
{
DateTime d1;
DateTime d2;
for (int i = 0; i < dataGridView1.RowCount - 1; i++)
{
d1 = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); // date now
d2 = Convert.ToDateTime(dataGridView1.Rows[i].Cells[5].Value); // expiry date column
TimeSpan ts = d2- d1;
dataGridView1.Rows[i].Cells[9].Value = ts.Days;
string Query3 = "Update Medicine set DaysLeft ='" + ts.Days + "'" + " where rowid ='" + dataGridView1.Rows[i].Cells[0].Value + "'";
ExcecuteQuery(Query3);
LoadData();
}
}
【问题讨论】:
-
“出了点问题” 怎么了?我看过图片,但我不知道是什么问题
-
问题是最后一列倒计时在天后过期
-
它没有显示正确的过期天数
-
我已经更正了我的问题
-
使用调试器查看 d1、d2 和 ts 的值。使用参数避免sql注入和格式错误。
标签: c#