【发布时间】:2012-03-10 19:29:37
【问题描述】:
我的 DataGridView 通过 SqlDataReader 绑定到数据库查询结果,当我测试 null 的单元格值时,我得到了意想不到的结果。
我的代码是这样的:
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");
}
即使数据库中的值为 null,我也会得到输出 Already Paid。
【问题讨论】:
-
调试时,值显示为什么?
-
@StingyJack - 这与 OP 的假设完全相反。他假设 NULL 表示未付款。它可以是一个指示支付日期的列,因此 NULL 是指示没有支付日期的完美方式。
-
是的,我显然有一个星期一的案例。
标签: c# .net sql ado.net datagridview