错误如下:
无法将类型为“System.DBNull”的对象强制转换为类型“System.String”。
数据库中字段为: minzu 类型:nvarchar(3)
用dataAdapter提取出来存入datatable,然后提取这个字段的数据代码如下
DataSet1.MemberInfo2Row member = table[0]; //member为已被添充的table中的dataRow
string m_minzu=member.minzu;
编译没有错误,运行后出现这个错误
问大虾
无法将类型为“System.DBNull”的对象强制转换为类型“System.String”。
数据库中字段为: minzu 类型:nvarchar(3)
用dataAdapter提取出来存入datatable,然后提取这个字段的数据代码如下
DataSet1.MemberInfo2Row member = table[0]; //member为已被添充的table中的dataRow
string m_minzu=member.minzu;
编译没有错误,运行后出现这个错误
问大虾
另可以这样
//....
DataSet ds=....
DataTable dt=ds.Tables[0];
string st = dt.Rows[0]["lcid"].ToString();
-------------------------
如果是在获取的时候,那就初始化输入参数
DataSet1.MemberInfo2Row member = table[0]; //member为已被添充的table中的dataRow
-----------------------------------》
member = table.rows[0]; string m_minzu=member.minzu;
-------------->
string m_minzu=member["minzu"].tostring();
string m_minzu="";
if(member.minzu.isDBNull())//这个判断写的格式不一定,但是应该可以判断出来member.minzu是否为空的
{
m_minzu="";
}
else
{
m_minzu=member.minzu;}
DataSet1.MemberInfo2Row member = table[0]; //member为已被添充的table中的dataRow
if(member.IsNull(member.minzu) == false)//不为空
string m_minzu=member.minzu;
编译没有错误,运行后出现这个错误