using System; using System.Data; using System.Data.SqlClient; using System.Configuration; namespace admin.CommonClass { /// <summary> /// 连结数据库的类--OpenDB /// </summary> public class OpenDB { //获得连结数据库的字符串 private string strJet = ConfigurationSettings.AppSettings["strConn"]; public OpenDB() { // // TODO: 在此处添加构造函数逻辑 // } #region 获得DataSet /// <summary> /// 获得一个DataSet,格式:GetDataSet(查询字段,查询表,条件字段,条件符号,条件值) /// </summary> /// <param name="strZDName"></param> /// <param name="strTableName"></param> /// <param name="strWhereValue"></param> /// <returns></returns> public DataSet GetDataSet(string strZDName,string strTableName,string strWhereValue) { //创建连结数据库的对象 SqlConnection myconn = new SqlConnection(strJet); //创建Adapter对象 SqlDataAdapter myAdapter = new SqlDataAdapter("sp_GetDataSet",myconn); //指明为存储过程 myAdapter.SelectCommand.CommandType = CommandType.StoredProcedure; //给存储过程的strZD变量赋值,即指明查询字段. myAdapter.SelectCommand.Parameters.Add("@ZDName",SqlDbType.Char).Value = strZDName; //给存储过程的FromWhere变量赋值,即指明查询表. myAdapter.SelectCommand.Parameters.Add("@TableName",SqlDbType.Char).Value = strTableName; //给存储过程的WhereValue变量赋值,即指明查询条件. myAdapter.SelectCommand.Parameters.Add("@WhereValue",SqlDbType.Char).Value = strWhereValue; //创建DataSet对象 DataSet ds = new DataSet(); //填充数据 myAdapter.Fill(ds,"strFromWhere"); //返回一个DataSet return ds; |