在DB.aspx.cs的源码是这样的:
public class DB
{
public static OleDbConnection Getconn()
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["ConnectionString"].ToString()));
if (conn.State.Equals(ConnectionState.Closed))
{
conn.Open();
}
return conn;
}
private static void closeConnection()
{
OleDbConnection conn = DB.Getconn();
OleDbCommand cmd = new OleDbCommand();
if (conn.State == ConnectionState.Open)
{
conn.Close();
conn.Dispose();
cmd.Dispose();
}
}
public static void binddatalist(string sql, DataList dl)
{
try
{
OleDbConnection conn = DB.Getconn();
DataSet ds = getdataset(sql);
dl.DataSource = ds.Tables[0].DefaultView;
dl.DataBind();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
}
}
然后在网页的后台引用如下:
string topsql1 = "select top 10 * from info
order by hits,id desc";//教育动态
DB.binddatalist(topsql1, this.DataList1);
时而可以运行,时而出现上面所说的情况。为什么?怎么解决?谢谢!!
[[it] 本帖最后由 yeyuanzhi 于 2008-8-14 16:11 编辑 [/it]]