日期:2014-05-17 浏览次数:20445 次
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// DataBase 数据层类
/// </summary>
public class DataBase
{
public DataBase()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//创建连接对象
private SqlConnection con;
// 打开数据库连接
private void open()
{
if (con == null)
{
con = new SqlConnection("Data Source=localhost;DataBase=shujuku;Integrated Security=True");
}
if (con.State == System.Data.ConnectionState.Closed)
con.Open();
}
//关闭数据库链接
private void close()
{
if (con != null)
con.Close();
}
//释放数据库链接资源
public void Dispose()
{
if (con != null)
{
con.Dispose();
con = null;
}
}
// 传入参数并且转换为SqlParameter类型
public SqlParameter MakeInParam(string ParamName, SqlDbType DbType, int Size, object Value)
{
return MakeParam(ParamName, DbType, Size, ParameterDirection.Input, Value);
}
public SqlParameter MakeParam(string ParamName, SqlDbType DbType, Int32 Size, ParameterDirection Direction, object Value)
{
SqlParameter param;
if (Size > 0)
param = new SqlParameter(ParamName, DbType, Size);
else
&nbs