I\'m trying to execute a stored procedure and then use an if statement to check for null values and I\'m coming up short. I\'m a VB guy so please bear with me if I\'m making
This should work.
if (rsData["usr.ursrdaystime"] != System.DBNull.Value))
{
strLevel = rsData["usr.ursrdaystime"].ToString();
}
also need to add using statement, like bellow:
using (var objConn = new SqlConnection(strConnection))
{
objConn.Open();
using (var objCmd = new SqlCommand(strSQL, objConn))
{
using (var rsData = objCmd.ExecuteReader())
{
while (rsData.Read())
{
if (rsData["usr.ursrdaystime"] != System.DBNull.Value)
{
strLevel = rsData["usr.ursrdaystime"].ToString();
}
}
}
}
}
this'll automaticly dispose (close) resources outside of block { .. }.
Yes, just a syntax problem. Try this instead:
if (reader["usr.ursrdaystime"] != DBNull.Value)
.Equals()
is checking to see if two Object instances are the same.
The closest equivalent to your VB would be (see this):
Convert.IsDBNull()
But there are a number of ways to do this, and most are linked from here