Reader获取值的时候改成这样:string field = reader[0]==DBNull.Value?null:reader.GetString(0);

解决方案 »

  1.   

    if not isdbnull(你的数据库的值)then
       变量名=你的数据库的值
    end if
      

  2.   

    string field=reader.IsDBNull(0)?"":reader.GetString(0)
    or
    int field=reader.IsDBNull(0)?0:reader.GetInt32(0)
      

  3.   

    if dr("field") is dbnull.value then
        ' 数据库存储的是NULL值,不能给除了类型定义为object的其它类型的变量赋值
    end if
      

  4.   

    可以修改sql语句来达到目的:
    select col1,col2,isnull(col3,'') from tab1
    字段为空值时,转为空字符串输出
      

  5.   

    DBNull.Value就是数据库的空值,直接转换是不行的,不过你可以通过判读,然后给String赋值,如:C# :
    SqlDataReader reader = ...string str = reader[0]==DBNull.Value?null:reader.GetString(0);VB.Net:
    Dim reader = ...
    Dim Str As Stringif reader(0) = DBNull.Value then
      str = nothing
    else
      str = reader.GetString(0)
    end if