关于DataView显示数据库详细信息的问题

点击链接后产生的问题如下:

索引 0 不是非负数且小于总行数。

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.IndexOutOfRangeException: 索引 0 不是非负数且小于总行数。

源错误:

行 26: 				<asp:Label id="Label4" style="Z-INDEX: 107; LEFT: 280px; POSITION: absolute; TOP: 168px" runat="server"
行 27: 					Width="48px" Height="32px">项目号</asp:Label>
行 28: 				<asp:Label id=XM_NAME style="Z-INDEX: 106; LEFT: 368px; POSITION: absolute; TOP: 112px" runat="server" Width="121px" Height="32px" Text='<%# DataBinder.Eval(dataView1, "[0].XM_NAME", "{0}") %>'>
行 29: 				</asp:Label>
行 30: 				<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 64px; POSITION: absolute; TOP: 48px" runat="server"

偶的主要源代码如下:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace test8
{
 /// <summary>
 /// WebForm1 的摘要说明。
 /// </summary>
 public class WebForm1 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Label Label1;
  protected System.Web.UI.WebControls.TextBox TextBox1;
  protected System.Web.UI.WebControls.Button Button1;
  protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
  protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
  protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
  protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
  protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
  protected System.Data.OleDb.OleDbConnection oleDbConnection1;
  protected test8.DataSet1 dataSet11;
  protected System.Data.DataView dataView1;
  protected System.Web.UI.WebControls.Label Label2;
  protected System.Web.UI.WebControls.Label Label4;
  protected System.Web.UI.WebControls.Label Label5;
  protected System.Web.UI.WebControls.Label Label8;
  protected System.Web.UI.WebControls.Label XM_NAME;
  protected System.Web.UI.WebControls.Label XM_ID;
  protected System.Web.UI.WebControls.Label JZ_AWARD;
  protected System.Web.UI.WebControls.Label XM_BRIEF;
  protected System.Web.UI.WebControls.DataGrid DataGrid1;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
  
  }

此处省略WEB窗体设计器生成的代码

private void Button1_Click(object sender, System.EventArgs e)
  {
   string sql_str1=TextBox1.Text;
   if(TextBox1.Text!="")
    oleDbDataAdapter1.SelectCommand.CommandText="SELECT * FROM T_LS_HISTORYINFO WHERE (XM_NAME LIKE '%" +sql_str1+"%')";
   oleDbDataAdapter1.Fill(dataSet11,"T_LS_HISTORYINFO");
   DataGrid1.DataSource=dataSet11.Tables["T_LS_HISTORYINFO"].DefaultView;
   DataGrid1.DataBind();
   oleDbConnection1.Close();

  }

  private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
  {
   oleDbDataAdapter1.Fill(dataSet11,"T_LS_HISTORYINFO");
   int index = DataGrid1.SelectedIndex;
   string key = DataGrid1.DataKeys[index].ToString();
   dataView1.RowFilter = DataGrid1.DataKeyField + "='" + key + "'";
   XM_NAME.DataBind();
   XM_ID.DataBind();
   JZ_AWARD.DataBind();
   XM_BRIEF.DataBind();
   
  }
 }
}

问题出在那里呀?

焦急万分、、

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值