using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.SessionState;
namespace Northwind
{
/// <summary>
/// DBAccess 的摘要说明。主要是数据库草错的方法,附带一些常用的小函数
/// </summary>
public class DBAccess
{
#region 变量声明
protected SqlConnection Conn;
protected DataSet DS;
protected SqlDataAdapter SDA;
protected SqlCommand SC;
protected SqlDataReader SDR;
protected HttpResponse Response;
protected HttpSessionState Session;
#endregion public DBAccess()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void Open()
{
try 
{
string ConnStr=System.Configuration.ConfigurationSettings.AppSettings["conn"].ToString().Trim();
Conn=new SqlConnection(ConnStr);
Conn.Open(); }
catch(Exception e)
{
WriteMessage(e.Message.ToString(),true,true);
}
}
public void Close()
{
try

if(Conn.State==ConnectionState.Open)
Conn.Close();
}
catch(Exception e)
{
WriteMessage(e.Message.ToString(),true,true);
}
}
public void Dispose()
{
if(DS!=null)
DS.Dispose();
if(SDA!=null)
SDA.Dispose();
if(SDR!=null)
{
if(!SDR.IsClosed)
SDR.Close();
}
}
public void Fill(string strSql)
{
try
{
Open();
SDA=new SqlDataAdapter(strSql,Conn);
DS=new DataSet();
SDA.Fill(DS);
}
catch(Exception e)
{
WriteMessage(e.Message.ToString().Trim(),true,true);
}
finally
{
Close();
Dispose();
}
} public void Fill(string TableName,string strSql)
{
try
{
Open();
SDA=new SqlDataAdapter(strSql,Conn);
DS=new DataSet();
SDA.Fill(DS,TableName);
}
catch(Exception e)
{
WriteMessage(e.Message.ToString().Trim(),true,true);
}
finally
{
Close();
Dispose();
}
}
public void BindDataGrid(string strSql,DataGrid DG)
{
try
{
Open();
Fill(strSql);
DG.DataSource=DS.Tables[0].DefaultView;
if(DG.CurrentPageIndex>DG.PageCount-1)
{
if(DG.PageCount>0)
DG.CurrentPageIndex=DG.PageCount-1;
else
DG.CurrentPageIndex=0;
}
DG.DataBind();
}
catch(Exception e)
{
WriteMessage(e.Message.ToString(),true,true);
}
finally
{
Close();
Dispose();
}
}
public void DeleteDGNotice(DataGrid DG)

if((DG.Items.Count%DG.PageSize==1)&&(DG.PageCount>1))
{
if(DG.PageCount>0)
DG.CurrentPageIndex=DG.CurrentPageIndex-1;
else
DG.CurrentPageIndex=0;
} }
public void BindDataGrid(string strSql,DataGrid DG,string ColumnName)
{
try
{
Open();
Fill(strSql);
DS.Tables[0].Columns.Add("KeyField");
for(int i=0;i<DS.Tables[0].Rows.Count;i++)
DS.Tables[0].Rows[i]["KeyField"]=HttpUtility.UrlEncode(DS.Tables[0].Rows[i]
[ColumnName].ToString().Trim());
DG.DataSource=DS.Tables[0].DefaultView;
if(DG.CurrentPageIndex>DG.PageCount-1)

if(DG.PageCount>0)
DG.CurrentPageIndex=DG.PageCount-1;
else
DG.CurrentPageIndex=0;
}
DG.DataBind();
} catch(Exception e)
{
WriteMessage(e.Message.ToString(),true,true);
}
finally
{
Close();
Dispose();
}

}
}
}
 
名称“WriteMessage”在类或命名空间“Northwind.DBAccess”中不存在,哪位高人帮帮我~~谢谢