我的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