S
sck10
Hello (converting from vb to c#),
Is there a way to test the value of null of a particular field of a dataset
from SQL Server? I am going through a dataset and trying to determine if
the value being sent is Null using IsDBNull. I am using the following:
if (! IsDBNull(spCurrentHighLgt["strTitle"])) this.ltlCHLTitle.Text =
spCurrentHighLgt["strTitle"].toString();
However, I am getting the error that the name "IsDBNull" does not exist in
the current context. I also tried the following, but am not sure if its
testing for what I want:
if (spCurrentHighLgt["strTitle"].ToString() != null) this.ltlCHLTitle.Text =
spCurrentHighLgt["strTitle"].toString();
Any help with this would be appreciated.
--
Thanks in advance,
sck10
full code:
//'Open connection to database
OleDbConnection cnnSearch = new OleDbConnection(strConn);
cnnSearch.Open();
//'Populate the data fields: Text Box
//'----------------------------------
OleDbParameter prmCurrentHighLgt;
OleDbCommand cmdSearch = new OleDbCommand(str00, cnnSearch);
cmdSearch.CommandType = CommandType.StoredProcedure;
//'Declare Parameters
prmCurrentHighLgt = cmdSearch.Parameters.Add("@strParm01",
OleDbType.VarChar); prmCurrentHighLgt.Value = str01;
using (OleDbDataReader spCurrentHighLgt = cmdSearch.ExecuteReader())
{
//'Test for records and to Unhide Submital Information
if (spCurrentHighLgt.HasRows) {
while (spCurrentHighLgt.Read())
{
if (spCurrentHighLgt["strTitle"].ToString() != null)
this.ltlCHLTitle.Text = spCurrentHighLgt["strTitle"].ToString();
if (spCurrentHighLgt["strContent"].ToString() != null)
this.ltlCHLContent.Text = spCurrentHighLgt["strContent"].ToString();
} //Loop
//this.SecurityHidePanels();
//this.pnlRecordsFound.Visible = true;
}
//'Close DataReader
spCurrentHighLgt.Close();
//'Close out connection to database
cnnSearch.Close();
}
Is there a way to test the value of null of a particular field of a dataset
from SQL Server? I am going through a dataset and trying to determine if
the value being sent is Null using IsDBNull. I am using the following:
if (! IsDBNull(spCurrentHighLgt["strTitle"])) this.ltlCHLTitle.Text =
spCurrentHighLgt["strTitle"].toString();
However, I am getting the error that the name "IsDBNull" does not exist in
the current context. I also tried the following, but am not sure if its
testing for what I want:
if (spCurrentHighLgt["strTitle"].ToString() != null) this.ltlCHLTitle.Text =
spCurrentHighLgt["strTitle"].toString();
Any help with this would be appreciated.
--
Thanks in advance,
sck10
full code:
//'Open connection to database
OleDbConnection cnnSearch = new OleDbConnection(strConn);
cnnSearch.Open();
//'Populate the data fields: Text Box
//'----------------------------------
OleDbParameter prmCurrentHighLgt;
OleDbCommand cmdSearch = new OleDbCommand(str00, cnnSearch);
cmdSearch.CommandType = CommandType.StoredProcedure;
//'Declare Parameters
prmCurrentHighLgt = cmdSearch.Parameters.Add("@strParm01",
OleDbType.VarChar); prmCurrentHighLgt.Value = str01;
using (OleDbDataReader spCurrentHighLgt = cmdSearch.ExecuteReader())
{
//'Test for records and to Unhide Submital Information
if (spCurrentHighLgt.HasRows) {
while (spCurrentHighLgt.Read())
{
if (spCurrentHighLgt["strTitle"].ToString() != null)
this.ltlCHLTitle.Text = spCurrentHighLgt["strTitle"].ToString();
if (spCurrentHighLgt["strContent"].ToString() != null)
this.ltlCHLContent.Text = spCurrentHighLgt["strContent"].ToString();
} //Loop
//this.SecurityHidePanels();
//this.pnlRecordsFound.Visible = true;
}
//'Close DataReader
spCurrentHighLgt.Close();
//'Close out connection to database
cnnSearch.Close();
}