totalhours
我目前正在以数据库的格式和从数据库中获取员工在一定时期内的总double
迟到,但问题是当我检查数据库时,可以说员工没有一条迟到的记录,这使得reader = null
. 所以,我决定使用isDBNull
,但是当我插入时if (!myReader.IsDBNull(myReader.GetDouble("total")))
,会myReader.Getdouble("total")
生成一个带有参数的错误
系统无法转换
double
为`int
cc.SetCMD(@"SELECT SUM(AccHours) AS total FROM mia_payroll.tbl_late WHERE COP_ID = @ID AND EID = @EID;");
using (myConn = new MySqlConnection(ConnectionClass.GetConnection()))
{
myConn.Open();
using (cmDB = new MySqlCommand(cc.GetCMD(), myConn))
{
cmDB.Parameters.AddWithValue("@ID", lblCOID.Text);
cmDB.Parameters.AddWithValue("@EID", EID);
try
{
using (myReader = cmDB.ExecuteReader())
{
while (myReader.Read())
{
if (!myReader.IsDBNull(myReader.GetDouble("total")))
{
total = myReader.GetDouble("total");
}
else
{
total = 0;
}
txtLate.Text = System.Convert.ToString(total);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
myConn.Close();
}