0
StackOverflowException未处理。我需要帮助。我上线StackOverflowException在SqlDataAdapter.Fill上未处理()
adp.Fill(ds)
错误此外,我不知道为什么,但我不能删除throw
,它返回一个值的所有代码说不。
string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["dbCustConn"].ToString();
string cmdStr = "Select * from MainDB";
public DAL() // default parameter. Use?
{
}
public DataTable Load() // what is this for? (loads all the records from the database)
{
SqlConnection conn = new SqlConnection(connStr);
//SqlCommand cmd = new SqlCommand(cmdStr, connStr);
SqlDataAdapter adp = new SqlDataAdapter(cmdStr, connStr); // SqlDataAdapater? Load all?
DataSet ds = new DataSet();
try
{
adp.Fill(ds);
return ds.Tables[0];
}
catch
{
throw;
}
finally
{
ds.Dispose();
adp.Dispose();
conn.Close();
conn.Dispose();
}
}
public DataTable Load() // what is this for? (loads all the records from the database)
{
SqlDataAdapter adp = new SqlDataAdapter(cmdStr, connStr); // SqlDataAdapater? Load all?
DataSet ds = new DataSet();
using(SqlConnection conn = new SqlConnection(connStr))
{
adp.Fill(ds);
return ds.Tables[0];
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
MasterCust.DataSource = GridDataSource();
MasterCust.DataBind();
//DetailCust.DataSource = ds2;
//DetailCust.DataBind();
}
private DataTable GridDataSource()
{
BAL p = new BAL();
DataTable dTable = new DataTable();
try
{
dTable = p.Load();
}
catch (StackOverflowException ee)
{
string message = ee.Message.ToString();
}
finally
{
p = null;
}
return dTable;
}
“没有返回值的所有代码。” - 如果你捕捉到一个异常但不重新抛出,那么它将从catch块中跳出到函数的结尾,而不通过'return'。你也可以使用'使用'块来重写try/finally,这可能会更清楚 - 你不需要关闭和处理连接,就足够处理了(因为我之前被告知) – Rup 2012-01-10 01:22:11
你能提供吗堆栈跟踪?您也可以从学习使用'语句中受益。 – 2012-01-10 01:23:13
我是新来的多层是这个代码。我如何获得堆栈跟踪?我通常做Label1.Text = ex.StackTrace.ToString()。 – healxph0enix 2012-01-10 01:34:31