错误如下:
  无法将类型为“System.DBNull”的对象强制转换为类型“System.String”。
数据库中字段为: minzu  类型:nvarchar(3)
  用dataAdapter提取出来存入datatable,然后提取这个字段的数据代码如下
  DataSet1.MemberInfo2Row member = table[0];  //member为已被添充的table中的dataRow
  string m_minzu=member.minzu;
编译没有错误,运行后出现这个错误  
问大虾

解决方案 »

  1.   

    MemberInfo2Row的代码?里面未对字段的值为<null>的情况进行处理
      

  2.   

    字段的值为空,他得到System.DBNull,你全部填上看:
    另可以这样
    //....
    DataSet ds=....
     DataTable dt=ds.Tables[0];
          string st = dt.Rows[0]["lcid"].ToString();
      

  3.   

    “System.DBNull
    -------------------------
    如果是在获取的时候,那就初始化输入参数
    DataSet1.MemberInfo2Row member = table[0];  //member为已被添充的table中的dataRow
    -----------------------------------》
    member = table.rows[0];  string m_minzu=member.minzu;
    -------------->
    string m_minzu=member["minzu"].tostring();
      

  4.   

    加个判断
     string m_minzu="";
    if(member.minzu.isDBNull())//这个判断写的格式不一定,但是应该可以判断出来member.minzu是否为空的
    {
    m_minzu="";
    }
    else
    {
     m_minzu=member.minzu;}
      

  5.   

    你要进行判断该行该列是否为空值,
    DataSet1.MemberInfo2Row member = table[0]; //member为已被添充的table中的dataRow
    if(member.IsNull(member.minzu) == false)//不为空
    string m_minzu=member.minzu;
    编译没有错误,运行后出现这个错误