An unhandled exception of type System.StackOverflowException occurred in mscorlib.dll
I wrote a code in ASP.NET that read data from SQL开发者_开发问答 Table and show it in Grid View and using Row Data Bound Event.But when I run the program, this exception arise "An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll" in indicated statement of the code:
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();
}
The RowDataBoundEvent handler is:
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')");
}
The BindAllUser Function is called here:
protected void Page_Load(object sender, EventArgs e)
{
BindAllUsers();
BindDropDown();
}
Try this:
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();
}
}
}
精彩评论