dt.Rows.Count的值始終等於1,並且dt.Rows [0] [0]和dt.Rows [0] [ 1]是空字符串,當我查詢沒有記錄的sqlStr。C#數據錶行值爲空字符串,但存在空值
但我在數據庫中執行sqlStr。它是空的。 Here is the database screenshot 我不知道它爲什麼。
string sqlStr = "select SUM(userIncome),SUM(userSpend) from tb_billlist where userPhone = '" + userPhone + "' and " +
"billTime between '" + beginDate + "' and '" + endDate + "'";
//execute sql
DataTable dt = new DataTable();
dt = MysqlHelper.ExecuteDataTable(sqlStr);
if (dt.Rows.Count > 0)
{
userBillInfo.userAllIncome = (float.Parse)(dt.Rows[0][0].ToString());
userBillInfo.userAllSpend = (float.Parse)(dt.Rows[0][1].ToString());
}
else
{
userBillInfo.userAllIncome = 0;
userBillInfo.userAllSpend = 0;
}
看起來像沒有行.. – BugFinder
我會*開始*通過修復SQL注入攻擊漏洞(或至少是轉換脆弱性,至少)你去那裏。使用參數化SQL,* always *。 –
因爲SUM()總是返回一些東西,所以你總會得到一行。 –