System.StackOverflowException未处理HResult = -2147023895 Message = Exception_WasThrown InnerException:
public partial class dridviewinser_update_Delete : System.Web.UI.Page
{
string connectstringweb = ConfigurationManager.ConnectionStrings["mydatabase"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
bindgridview();
}
private void bindgridview()
{
//this is property
SqlConnection con = new SqlConnection(connectstringweb);
con.Open();
string query = "gridview_select_bindgrid";
SqlCommand cmd = new SqlCommand(query, con);
cmd.CommandType = CommandType.StoredProcedure;
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
grdviewdata.DataSource = dt;
grdviewdata.DataBind();
con.Close();
bindgridview();
}
protected void btninsert_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectstringweb);
con.Open();
string query = "dridview_insert";
SqlCommand cmd = new SqlCommand(query, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@name", txtname);
cmd.Parameters.AddWithValue("@email", txtemail);
cmd.ExecuteNonQuery();
Response.Write("Insert Successfull!");
con.Close();
}
}
}
答案 0 :(得分:4)
您正在同一方法中调用bindgridview();
。因此,它会一遍又一遍地调用自己,直到堆栈溢出为止。
我无法通过您的代码告诉您哪种方法是合适的。你能从方法的底部删除那一行吗?或者你可能犯了一个错误,并打算调用另一种方法。无论哪种方式,如果您调试应用程序并逐步执行代码,您将看到它一遍又一遍地进入该方法而没有任何阻止它执行此操作。