DataGridViewがSqlDataReader
を介してデータベースクエリ結果にバインドされていて、null
のセル値をテストすると、予期しない結果が発生します。私は、データベースからの値がnullのであるにもかかわらず、すでに有料出力を取得していますDataGridviewのセル内のデータが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");
}
:
私のコードは次のようなものです。
を使用してみてください? – peroija
@StingyJack - これは、OPが想定しているものとまったく反対です。彼はNULLを支払わないことを意味すると仮定しています。これは、何かが支払われた日付を示す列である可能性があります。したがって、NULLは、支払日がないことを示す完全な方法です。 – GarethD
うん、私は明らかに月曜日の事件を持っている。 – StingyJack