我的DataGridView通過SqlDataReader
綁定到數據庫查詢結果,當我測試單元格值爲null
時,我得到意想不到的結果。檢查datagridview的單元格中的數據是否爲空
我的代碼是這樣的:
SqlConnection con = new SqlConnection(
"Data Source = .;Initial Catalog = SAHS;integrated security = true");
con.Open();
SqlCommand cmd3 = new SqlCommand(
"select Status from vw_stdtfeedetail
where Std= 6 and Div ='B' and name='bbkk' and mnthname ='June'", con);
SqlDataReader dr = cmd3.ExecuteReader();
BindingSource bs = new BindingSource();
bs.DataSource = dr;
dataGridView3.DataSource = bs;
this.monthFeeTableAdapter.Fill(this.sAHSDataSet4.MonthFee);
if (dataGridView3.CurrentCell.Value == null)
{
MessageBox.Show("Pending");
}
else
{
MessageBox.Show("Already Paid");
}
我得到的輸出已支付即使從數據庫中的值是空。
當你調試,什麼是價值顯示爲? – peroija 2012-02-20 13:06:02
@SingyJack - 這與OP所設想的完全相反。他假設NULL表示沒有付款。它可能是一個表示支付日期的列,因此NULL是指示沒有支付日期的完美方式。 – GarethD 2012-02-20 14:58:02
是的,我已經明確了一個星期一的例子。 – StingyJack 2012-02-20 15:52:43