473,379 Members | 1,260 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

IsDBNull

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

Jul 26 '06 #1
4 3997

"sck10" <sc***@online.nospamwrote in message
news:eN**************@TK2MSFTNGP04.phx.gbl...

Try,

if ( spCurrentHighLgt["strTitle"] == DBNull.Value )
{

}
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();
}
Jul 26 '06 #2
Convert.IsDBNull
"sck10" <sc***@online.nospamwrote in message
news:eN**************@TK2MSFTNGP04.phx.gbl...
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();
}

Jul 26 '06 #3
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...b;en-us;318039
Regards,
Walter Wang (wa****@online.microsoft.com, 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.

Jul 27 '06 #4
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

"sck10" <sc***@online.nospamwrote in message
news:eN**************@TK2MSFTNGP04.phx.gbl...
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();
}

Jul 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: jim | last post by:
This line of code returns error 13, cast from 'DBNull' to type 'String' is not valid If IsDBNull(Clinics.Clinics.Item(A).Workphone) The <other code End I Clinics.Clinics is a dataset that...
4
by: Jim | last post by:
I am having a problem with the IsDBNull function. When it checks what type of value is contained in the parameter that is passed to it, it does not successfully determine that it has a DBNull...
4
by: BillG | last post by:
I have the following line in my code paid.MonthsPaid = IIf(IsDBNull(Row("MonthsPaid")), Integer.MinValue, Convert.ToInt16(Row("MonthsPaid"))) and I get the error message Object cannot be...
5
by: luna | last post by:
how to i use isdbnull on two tables ? im pulling out the data with a stored procedure like this :- CREATE PROCEDURE search @search varchar(8) AS
1
by: et | last post by:
How do you know when to use isnull, and isdbnull and how do you use them? I have the following expression in C: DataRowView drv = dataItem as DataRowView; if (drv != null) How do I convert...
3
by: Paul D. Fox | last post by:
I have this code snippet below where I'm loading all the labels based upon the retrieved record from the DataReader. Unfortunatley, some of the values are null, so I can't explicitly set the...
4
by: Brad Isaacs | last post by:
I am using ASP.NET 2.0 codebehind Visual Basic, Visual Studio 2005 Working with DataSet creating a Data Access Layer via VS 2005. My error is when the code that is prewritten by VS 2005 Casts...
5
by: Rainer Queck | last post by:
Hello NG, I have a typed dataset, where I want to check the column of a datarow if it is DBNull. How can the following code cause an Exception (what is does): if...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.