關於DataView顯示資料庫詳細資料的問題

來源:互聯網
上載者:User
資料|資料庫|問題|顯示

點選連結後產生的問題如下:

索引 0 不是非負數且小於總行數。

說明: 執行當前 Web 請求期間,出現未處理的異常。請檢查堆疊追蹤資訊,以瞭解有關該錯誤以及代碼中導致錯誤的出處的詳細資料。

異常詳細資料: System.IndexOutOfRangeException: 索引 0 不是非負數且小於總行數。

源錯誤:

行 26:  <ASP:LABEL id=Label4 style="Z-INDEX: 107; LEFT: 280px; POSITION: absolute; TOP: 168px" Height="32px" Width="48px"
行 27:  runat="server">項目號</ASP:LABEL>
行 28:  <ASP:LABEL id=XM_NAME style="Z-INDEX: 106; LEFT: 368px; POSITION: absolute; TOP: 112px" Height="32px" Width="121px" runat="server" 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
{
 ///


 /// WebForm1 的摘要說明。
 ///
 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();
   
  }
 }
}

問題出在那裡呀?

焦急萬分、、



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。