如何检查DataRowView是否为null. [英] How to check DataRowView null or not.
本文介绍了如何检查DataRowView是否为null.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查DataRowView是否为null.我在这里出现错误源不包含DataRows".
How to check DataRowView null or not. I got error "The source contains no DataRows" here.
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drView = (DataRowView)e.Row.DataItem;
{
DataTable dtChildTable1 = ((DataTable)Session["dtAll"]).Select("ID=" + Convert.ToInt32(drView["ID"])).CopyToDataTable();
}
推荐答案
Its better if you use boolean AND operator as follow
if (if e.Row != null && e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drView = (DataRowView)e.Row.DataItem;
{
DataTable dtChildTable1 = ((DataTable) Session["dtAll"]);
if(dtChildTable1 != null)
{
DataTable dtNew = dtChildTable1.Select("ID=" + Convert.ToInt32( drView["ID"])).CopyToDataTable();
}
}
}
Or <br />
you can create a reference to the DataRow[] Array instead of dtNew variable of or better to use var
尝试(drView.Row != null)
.
关注链接
http://msdn.microsoft.com/en-us/library/system. data.datarow.isnull.aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/ms178296%28v = vs.80%29.aspx [ ^ ]
Follow the links
http://msdn.microsoft.com/en-us/library/system.data.datarow.isnull.aspx[^]
http://msdn.microsoft.com/en-us/library/ms178296%28v=vs.80%29.aspx[^]
这篇关于如何检查DataRowView是否为null.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文