+ -
当前位置:首页 → 问答吧 → There is no row at position 0.盼望过路大虾搭救!

There is no row at position 0.盼望过路大虾搭救!

时间:2011-12-17

来源:互联网

There is no row at position 0. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IndexOutOfRangeException: There is no row at position 0.

Source Error: 


Line 22: }
Line 23: DataTable dt = Sqlbase.ExecuteTable(CommandType.Text, "select * from book where id=" + Convert.ToInt32(Request["id"]), null);
Line 24: lbname.Text=dt.Rows[0]["name"].ToString();
Line 25: lbkit.Text = dt.Rows[0]["kit"].ToString();
Line 26: lborther.Text = dt.Rows[0]["author"].ToString();
 



作者: cbb_a   发布时间: 2011-12-17

23行的问题,断点调试看看select查询有没有查到数据

作者: zh6335901   发布时间: 2011-12-17

你查询出的表里没有记录
所以取值时要判断一下

DataTable dt = Sqlbase.ExecuteTable(CommandType.Text, "select * from book where id=" + Convert.ToInt32(Request["id"]), null);
if(dt.Rows.Count>0)
{
lbname.Text=dt.Rows[0]["name"].ToString();
lbkit.Text = dt.Rows[0]["kit"].ToString();
lborther.Text = dt.Rows[0]["author"].ToString();
}
else
{
lbname.Text="";
lbkit.Text ="";
lborther.Text = "";
}

作者: gxingmin   发布时间: 2011-12-17

if(dt.Rows.Count>0)
需要判断阿

作者: ximenwuji   发布时间: 2011-12-17

立马就解决啦!(*^__^*) 嘻嘻……!谢谢啦!

作者: cbb_a   发布时间: 2011-12-17