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

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;
}
 
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;



}- 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.
 
C

Cor Ligthert[MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top