【发布时间】:2017-08-14 21:40:52
【问题描述】:
我有一个访问数据库,存储每个员工上班的时间和员工离开的时间。我想计算用户在家工作的时间。这是我的代码:
DataTable dm = new DataTable();
today = DateTime.Today;
hooodorDa = new OleDbDataAdapter("select heUsers,heCome,heGo from HoodoorEnseraf where heDate=#" + today.ToString("yyyy/MM/dd") + "# and heUsers='" + heUsers.Text + "' ", connection);
hooodorDa.Fill(dm);
DateTime hec = Convert.ToDateTime(dm.Rows[0]["heCome"]);
DateTime heg = Convert.ToDateTime(dm.Rows[0]["heGo"]);
TimeSpan diff = hec - heg;
command = new OleDbCommand("update HoodoorEnseraf set heDifference=? where heUsers=? ;", connection);
command.Parameters.AddWithValue("?", diff);
command.Parameters.AddWithValue("?", heUsers.Text);
我需要在数字字段中插入值,如下面的屏幕截图所示,但我的代码给了我一个错误:
对象不能从 dbnull 转换为其他类型
我的代码有什么问题?
【问题讨论】:
-
你的问题是什么?我的意思是,很高兴你把代码放在这里你到目前为止尝试过的东西,但是用你发布的代码解释你的问题可能会给你的问题带来更多的回应
-
那里有什么问题? diff 值是否正确?
-
不,我收到此错误(对象无法从 dbnull 转换为其他类型
标签: c# ms-access error-handling