.net - mscorlib.dll 中出现类型为 System.StackOverflowException 的未处理异常

标签 .net asp.net

我在 ASP.NET 中编写了一段代码,该代码从 SQL 表中读取数据并在 GridView 中显示它并使用行数据绑定(bind)事件。但是当我运行该程序时,会出现此异常“'System.StackOverflowException 类型的未处理异常'出现在 mscorlib.dll 中”,在代码的指定语句中:

    private void BindAllUsers()
    {
        SqlDataAdapter da = new SqlDataAdapter("SELECT ID, Name, Email, Password, Contact, CreatedOn, CreatedBy,CreatedIP From tbl_Users",con);
        DataSet ds = new DataSet();
        da.Fill(ds);       <------(Error occurs in this line)
        gdv_Users.DataSource = ds;
        gdv_Users.DataBind();

    }

RowDataBoundEvent 处理程序是:

    protected void gdv_Users_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Style["Cursor"] = "hand";
        e.Row.Cells[0].ToolTip = "Click Here";
        e.Row.Cells[0].Attributes.Add("onclick","window.open('Details.aspx'?ID=" + e.Row.Cells[0].Text.ToString()+"'Details';'width = 735,height= 350,left = 220,top = 300,resizable = 0,scrollbars = 0,status = no')");
    }

BindAllUser 函数在这里被调用:

 protected void Page_Load(object sender, EventArgs e)
{
    BindAllUsers();
    BindDropDown();

}

最佳答案

试试这个:

        private void BindAllUsers()
    {
        using (SqlConnection con = new SqlConnection("connection string"))
        {
            con.Open();
            SqlCommand command = new SqlCommand();
            command.Connection = con;
            command.CommandText = "SELECT ID, Name, Email, Password, Contact, CreatedOn, CreatedBy,CreatedIP From tbl_Users";
            SqlDataReader dr = command.ExecuteReader();
            if (dr.HasRows)
            {
                gdv_Users.DataSource = ds;
                gdv_Users.DataBind();
            }
        }

    }

关于.net - mscorlib.dll 中出现类型为 System.StackOverflowException 的未处理异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6645314/

相关文章:

c# - Assembly.GetCustomAttributes 仍然被认为是最佳方法吗?

c# - 使用 Guid 和自定义表名称与 Asp.net Identity 1.1 Alpha 创建自定义实现

javascript - 检测浏览器关闭所有条件

.net - ImageList 透明度错误的解决方法?

c# - 如何从 Access .mdb 文件创建 .edmx 模型?

c# - 有没有其他方法可以在不使用 WebRequestMethods.Ftp.ListDirectory 方法的情况下测试 FTP 服务器的连接?

ASP.NET MVC 认为我的虚拟目录是一个 Controller

asp.net - 我可以更改 ASP.Net MVC 3 应用程序物理 View 的搜索顺序吗

c# - ReSharper 中修改的关闭警告

c# - 为什么在使用 OleDb 导入 Excel 时忽略第一个空行