IsDBNull

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();
}
 
W

Walter Wang [MSFT]

You may also check out following articles for more information on DBNull:

#Handling Null Values
http://msdn2.microsoft.com/en-us/library/ms172138.aspx

#How To: Make a Typed DataSet Return a Default Value Instead of DBNull by
Using Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;318039


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

Ken Fine

This is an indirect answer to your question... but.... if you use an
object-relational mapping framework such as dOOdads (free, great), it builds
a bunch of so-called "string methods" for your data fields, and you can test
easily against those. Just another option to look at in addition to the
other suggestions folks have made.

-KF
 

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