Questions about DataView displaying database details

Source: Internet
Author: User
Tags stack trace
Data | database | problem | show

Clicking on the link creates the following questions:

Index 0 is not non-negative and is less than the total number of rows.

Note: An unhandled exception occurred during the execution of the current WEB request. Check the stack trace for more information about the error and where the error occurred in the code.

Exception Details: system.indexoutofrangeexception: Index 0 is not a non-negative number and is less than the Total row count.

SOURCE Error:

Line: <asp:label id=label4 style= "z-index:107; left:280px; Position:absolute; top:168px "height=" 32px "width=" 48px "
Row 27:runat= "Server" > Project number </ASP:LABEL>
Row: <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} ")%> ' >
Line: </ASP:LABEL>
Line: <asp:textbox id=textbox1 style= "Z-INDEX:101; left:64px; Position:absolute; top:48px "runat=" Server "

My main source code is as follows:

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 description of the 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)
{

}

The code generated by the Web Forms Designer is omitted here

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 ();

}
}
}

Where's the problem?

Anxious,



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.