DBNull if statement

前端 未结 9 1539
再見小時候
再見小時候 2020-12-01 13:55

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

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 14:04

    The idiomatic way is to say:

    if(rsData["usr.ursrdaystime"] != DBNull.Value) {
        strLevel = rsData["usr.ursrdaystime"].ToString();
    }
    

    This:

    rsData = objCmd.ExecuteReader();
    rsData.Read();
    

    Makes it look like you're reading exactly one value. Use IDbCommand.ExecuteScalar instead.

提交回复
热议问题