On 9 Mar 2004 05:32:02 -0800,
(E-Mail Removed) (troutbum) wrote:
> I used a sqlreader to verify
> that the field was returning "", as per my stored procedure
> IsNull(field, '') as Field returned.
Here's how I deal with that pesky "DBNull is not a string" problem:
public static string executeStrScalar(string sSQL)
{
string tmp = "";
object obj = new object(); <--- HERE
try
{
HERE ---> obj = SqlHelper.ExecuteScalar
(strCon, CommandType.Text, sSQL);
HERE ---> if (obj != null)
tmp = Convert.ToString(obj);
}
catch(Exception e)
{
string s = String.Format
( "AccessDistractors:getDistractorTextForId: "
+ "Unexpected database error {0}.\n"
+ "SQL = {1}."
, e.Message
, sSQL
);
throw new ApplicationException(s);
}
return tmp;
}
By setting the return from the DAAB equal to a plain old object, I get
the chance to check it for null and *then* convert it to a string.
-- Rick