当前位置:编程学习 > C#/ASP.NET >>

GridView IListSource 不包含任何数据源 //请哪位大侠帮帮忙

 try
        {
            SqlData da = new SqlData();
            string cmdtxt1 = "select * from tb_WorkSum";
            this.GridView1.DataSource = da.ExceDS(cmdtxt1, "tb_WorkSum");
            this.GridView1.DataKeyNames = new string[] { "ID" };
            //this.GridView1.PageIndex = d.NewPageIndex;
            this.GridView1.DataBind();
            if (!IsPostBack)
            {
                string cmdtxt2 = "select Distinct Name from Users";
                SqlDataReader dr = da.ExceDr(cmdtxt2);
                while (dr.Read())
                {
                    this.dropSumMan.Items.Add(dr["Name"].ToString());
                }
                dr.Close();
                string cmdtxt3 = "select Distinct DepName from tb_Department";
                SqlDataReader dr2 = da.ExceDr(cmdtxt3);
                while (dr2.Read())
                {
                    this.dropDepName.Items.Add(dr2["DepName"].ToString());
                }
                dr2.Close();
            }
        }
        finally
        {
            Response.Write("<script language=javascript>alert('数据为空!');location='WorkSum.aspx'</script>");   
        }
在tb_WorkSum 表中有数据,使用"select * from tb_WorkSum"也能查询到数据,但是在上代码中还是提示IListSource 不包含任何数据源。

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

异常详细信息: System.Web.HttpException: IListSource 不包含任何数据源。

源错误: 


行 33:             this.GridView1.DataKeyNames = new string[] { "ID" };
行 34:             //this.GridView1.PageIndex = d.NewPageIndex;
行 35:             this.GridView1.DataBind();
行 36:             if (!IsPostBack)
行 37:             {
 

源文件: e:\Asp.net\EnterpriseManage\Module\ProRes\WorkSum.aspx.cs    行: 35 

堆栈跟踪: 


[HttpException (0x80004005): IListSource 不包含任何数据源。]
   System.Web.UI.DataSourceHelper.GetResolvedDataSource(Object dataSource, String dataMember) +393
   System.Web.UI.WebControls.ReadOnlyDataSource.System.Web.UI.IDataSource.GetView(String viewName) +38
   System.Web.UI.WebControls.DataBoundControl.ConnectToDataSourceView() +226
   System.Web.UI.WebControls.DataBoundControl.GetData() +4
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +57
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
   System.Web.UI.WebControls.GridView.DataBind() +4
   Module_Employee_ProRes_WorkSum.Page_Load(Object sender, EventArgs e) in e:\Asp.net\EnterpriseManage\Module\ProRes\WorkSum.aspx.cs:35
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

 


--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.1433; ASP.NET 版本:2.0.50727.1433  --------------------编程问答-------------------- ExceDS怎么写的 --------------------编程问答--------------------               string cmdtxt1 = "select * from tb_WorkSum";
是这样        this.GridView1.DataSource = da.ExceDS(cmdtxt1, "tb_WorkSum"); --------------------编程问答--------------------     public DataSet ExceDS(string cmdtxt,string tblName)
    {
        SqlConnection Con = ExceCon();
        SqlCommand Com;
        DataSet ds=null;
        try
        {
            Com = new SqlCommand(cmdtxt, Con);
            SqlDataAdapter Da = new SqlDataAdapter();
            Da.SelectCommand = Com;
            ds = new DataSet(tblName);
            Da.Fill(ds);
        }
        catch (Exception ex)
        {
            Con.Close();
        }
        return ds;
    }
    #endregion
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,