資料|資料庫|問題|顯示
點選連結後產生的問題如下:
索引 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();
}
}
}
問題出在那裡呀?
焦急萬分、、