【C#】 “万能”函数

      public static DataTable SelectSqlReturnTable(string sql, CommandType type, SqlParameter[] pars)
      {
          SqlConnection con = new SqlConnection(ConnString);
          SqlDataAdapter sda = new SqlDataAdapter(sql, con);
          sda.SelectCommand.CommandType = type;
          if (pars != null && pars.Length > 0)
          {
              foreach (SqlParameter p in pars)
              {
                  sda.SelectCommand.Parameters.Add(p);
              }
          }
          DataTable dt = new DataTable();
          sda.Fill(dt);
          return dt;
      }
posted @ 2012-07-19 16:53  net小伙  阅读(296)  评论(0编辑  收藏  举报