object无法从dbnull转换为c#net中的其他类型 [英] object cannot be cast from dbnull to other types in c# net
本文介绍了object无法从dbnull转换为c#net中的其他类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误:-object无法从dbnull转换为c#net中的其他类型
错误行:-st.Append(
Error:-object cannot be cast from dbnull to other types in c# net
Error Line:-st.Append("
foreach (DataRow item in dt.Rows)
{
// while (dr1.Read())
foreach (string s in List)
{
// var arr = s;
if (s != "S-1")
{
if (s == item["locationNo"])
{
st.Append("<td style="\"" mode="hold" /> st.Append("<td style="\"" mode="hold" /> st.Append("<td style="\"" mode="hold" /> }
else
{
st.Append("");
st.Append("<tr>");
st.Append("<td style="\"" mode="hold" /> st.Append("<td style="\"" mode="hold" /> st.Append("<td style="\"" mode="hold" />
}
}
}
st.Append("</tr>");
}
}
dr.Close();
st.Append("");
Literal1.Text = st.ToString();
推荐答案
尝试更改
Try changing
if (s == item["locationNo"])
to
to
if (!DBNull.Value.Equals(item["locationNo"]) && s == (string)item["locationNo"])
希望这会有所帮助,
Fredrik
Hope this helps,
Fredrik
这篇关于object无法从dbnull转换为c#net中的其他类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文