using System; using System.Data; using System.Data.SqlClient; namespace SysClassLibrary { /// <summary> /// DataAccess 的摘要说明。 /// <description>数据处理基类,调用方式:DataAccess.DataSet((string)sqlstr);或者DataAccess.DataSet((string)sqlstr,ref DataSet ds); </description> /// </summary> public class DataAccess { #region 属性 protected static SqlConnection conn=new SqlConnection(); protected static SqlCommand comm=new SqlCommand(); #endregion public DataAccess() { //init(); } #region 内部函数 静态方法中不会执行DataAccess()构造函数 /// <summary> /// 打开数据库连接 /// </summary> private static void openConnection() { if (conn.State == ConnectionState.Closed) { //SysConfig.ConnectionString 为系统配置类中连接字符串,如:"server=localhost;database=databasename;uid=sa;pwd=;" conn.ConnectionString = SysConfig.ConnectionString ; comm.Connection =conn; try { conn.Open(); } catch(Exception e) { throw new Exception(e.Message); } } } /// <summary> /// 关闭当前数据库连接 /// </summary> private static void closeConnection() { if(conn.State == ConnectionState.Open) conn.Close(); conn.Dispose(); comm.Dispose(); } #endregion /// <summary> /// 执行Sql查询语句 /// </summary> /// <param name="sqlstr">传入的Sql语句</param> public static void ExecuteSql(string sqlstr) { |