"'System.DBNull' is a 'type', which is not valid in the given context" - aka what type is DataRow co

  • Thread starter Thread starter mark4asp
  • Start date Start date
M

mark4asp

'System.DBNull' is a 'type', which is not valid in the given context

If dr["OfficeName"] is not an object then what is it? It is certainly
not a string because it hasn't yet been cast as one.

private void PopulateControls()
{
//If this is in AddMode then the table will be empty
if (_dsData.Tables["consultant_office"] != null &&
_dsData.Tables["consultant_office"].Rows.Count == 1)
{
DataRow dr = _dsData.Tables["Consultant_Office"].Rows[0];
txtOfficeName.Text = CheckNull(dr["OfficeName"]);
txtAddress.Text = CheckNull(dr["Address"]);
txtTel.Text = CheckNull(dr["Tel"]);
txtFax.Text = CheckNull(dr["Fax"]);
txtEmail.Text = CheckNull(dr["Email"]);
txtURL.Text = CheckNull(dr["URL"]);
chkDefault.Checked = (bool)dr["Default"];
}
}

private string CheckNull(object dataColumn)
{
if (dataColumn == System.DBNull)
return "";
else
return (string)dataColumn;
}
 
'System.DBNull' is a 'type', which is not valid in the given context

If dr["OfficeName"] is not an object then what is it? It is certainly
not a string because it hasn't yet been cast as one.

private void PopulateControls()
{
//If this is in AddMode then the table will be empty
if (_dsData.Tables["consultant_office"] != null &&
_dsData.Tables["consultant_office"].Rows.Count == 1)
{
DataRow dr = _dsData.Tables["Consultant_Office"].Rows[0];
txtOfficeName.Text = CheckNull(dr["OfficeName"]);
txtAddress.Text = CheckNull(dr["Address"]);
txtTel.Text = CheckNull(dr["Tel"]);
txtFax.Text = CheckNull(dr["Fax"]);
txtEmail.Text = CheckNull(dr["Email"]);
txtURL.Text = CheckNull(dr["URL"]);
chkDefault.Checked = (bool)dr["Default"];
}

}

private string CheckNull(object dataColumn)
{
if (dataColumn == System.DBNull)
return "";
else
return (string)dataColumn;



}- Hide quoted text -

- Show quoted text -

No need to reply. I see my error now. It's System.DBNull.Value

My apologies for wasting anyone's time.
 
Mark,

Thanks for sending this correction, I wished everybodies behaviour was like
that.

Cor

mark4asp said:
'System.DBNull' is a 'type', which is not valid in the given context

If dr["OfficeName"] is not an object then what is it? It is certainly
not a string because it hasn't yet been cast as one.

private void PopulateControls()
{
//If this is in AddMode then the table will be empty
if (_dsData.Tables["consultant_office"] != null &&
_dsData.Tables["consultant_office"].Rows.Count == 1)
{
DataRow dr = _dsData.Tables["Consultant_Office"].Rows[0];
txtOfficeName.Text = CheckNull(dr["OfficeName"]);
txtAddress.Text = CheckNull(dr["Address"]);
txtTel.Text = CheckNull(dr["Tel"]);
txtFax.Text = CheckNull(dr["Fax"]);
txtEmail.Text = CheckNull(dr["Email"]);
txtURL.Text = CheckNull(dr["URL"]);
chkDefault.Checked = (bool)dr["Default"];
}

}

private string CheckNull(object dataColumn)
{
if (dataColumn == System.DBNull)
return "";
else
return (string)dataColumn;



}- Hide quoted text -

- Show quoted text -

No need to reply. I see my error now. It's System.DBNull.Value

My apologies for wasting anyone's time.
 
Back
Top