C#のDataGridViewでnullセルの値を確認するにはどうすればよいですか?私はチェックのためにDBNullを使用しましたが、動作していないし、 "オブジェクト参照がオブジェクトのインスタンスに設定されていません"というエラーが発生しています。 私はVS2010を使用しています。DataGridViewのNull値
誰も私を助けることができますか?
DateGridViewは、次のプロパティがあります。 名前:dgTelFax AllowUserToAddRows:真 AllowUserToDeleteRows:真
を私が現在持っているコードは次のとおりです。事前に
DataSet objDSTelephone = new DataSet();
DataTable objDTTelephone = objDSTelephone.Tables.Add();
string strTelephoneID = "";
string strTelephone = "";
int intRecTel = dgTelFax.Rows.Count;
if (intRecTel > 0)
{
//-- Add columns to the data table
objDTTelephone.Columns.Add("id", typeof(string));
objDTTelephone.Columns.Add("telephone", typeof(string));
for (int i2 = 0; i2 <= intRecTel - 1; i2++)
{
strTelephoneID = (!DBNull.Value.Equals(dgTelFax.Rows[i2].Cells[0].Value)) ? dgTelFax.Rows[i2].Cells[0].Value.ToString() : "";
strTelephone = (!DBNull.Value.Equals(dgTelFax.Rows[i2].Cells[2].Value)) ? dgTelFax.Rows[i2].Cells[2].Value.ToString() : "";
objDTTelephone.Rows.Add(strTelephoneID, strTelephone);
}
}
感謝!!
これをチェックhttp://stackoverflow.com/questions/3155684/handle-empty-cells-in-datagridviewを – Raymund