我目前从数据库中获得了一定数量的员工在totalhours
和double
的格式下的总体评分,但是问题出在我检查数据库并让员工没有记录后期这使得reader = null
。所以,我决定用isDBNull
,但是当我插入if (!myReader.IsDBNull(myReader.GetDouble("total")))
,该myReader.Getdouble("total")
有一种说法认为reader.GetDouble需要int?
系统不能转换
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();
}