C#中没有行位置 [英] No row position in C#
本文介绍了C#中没有行位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
发生错误0位没有排
我尝试过:
there is error occurred "There is no row at position 0"
What I have tried:
i try this code
if (ds.Tables[0].Rows[0]["NRType"].ToString() == "0002")
{
ReportObj.ReportFileName = "report1.rpt";
}
else if (ds.Tables[0].Rows[0]["NRType"].ToString() == "0011")
{
ReportObj.ReportFileName = "report2.rpt";
}
else if (ds.Tables[0].Rows[0]["NRType"].ToString() == "0007")
{
ReportObj.ReportFileName = "report3.rpt";
}
Any solutions?
推荐答案
在使用前验证对象
Validate the objects before usage
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
string nrType = ds.Tables[0].Rows[0]["NRType"] + "";
if(nrType =="0002" )
ReportObj.ReportFileName = "report1.rpt";
else if (nrType =="0011")
ReportObj.ReportFileName = "report2.rpt";
else if (nrType == "0007")
ReportObj.ReportFileName = "report3.rpt";
}
这篇关于C#中没有行位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文