日期:2014-05-16  浏览次数:20459 次

Asp.net中DateReader读取数据库操作类!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;        // WebConfigurationManager
using System.Web.Configuration;    // WebConfigurationManager
using System.Text;     //  stringbuilder引用

    public class Sql_Class
    {
        static rigndael ri = new rigndael();
        #region ===================================== \\ ★ 【操作数据库  -- DataReader类 -- Select】
            public SqlDataReader Sql_Select(string sql)   // 读取数据类 - [Select语句]
            {
                 
                string connectionString =ri.Decrypto( WebConfigurationManager.ConnectionStrings["bds0040263_dbConnectionString"].ConnectionString);
                SqlConnection con = new SqlConnection(connectionString);

                try
                {
                    // ========================== \\ 打开
                    con.Open();

                }
                catch (Exception ex)
                {
                    // ========================== \\ 如果出错
                }
                finally
                {
                }

                SqlCommand cmd = new SqlCommand(sql, con);  // 执行Sql语句

                SqlDataReader dr = cmd.ExecuteReader();
                return dr;

            }
        #endregion

        #region ===================================== \\ ★ 【操作数据库  -- DataReader类 -- Update和Delete】

            public SqlDataReader Sql_Update_Delete(string sql)   // 读取数据类 - [Update和Delete]
            {
                string connectionString = ri.Decrypto(WebConfigurationManager.ConnectionStrings["bds0040263_dbConnectionString"].ConnectionString);
                SqlConnection con = new SqlConnection(connectionString);

                try
                {
                    // ========================== \\ 打开
                    con.Open();

                }
                catch (Exception ex)
                {
                    // ========================== \\ 如果出错
                }
                finally
                {
                }

                SqlCommand cmd = new SqlCommand(sql, con);  // 执行Sql语句

                SqlDataReader dr = cmd.ExecuteReader();
                return dr;

            }
        #endregion

        #region ===================================== \\ ★ 【操作数据库  -- DataReader类 -- 存储过程】

            public SqlDataReader Sql_Proc(string sql)   // 读取数据类 - [存储过程]
            {
                string connectionString = WebConfigurationManager.ConnectionStrings["bds0040263_dbConnectionString"].ConnectionString;
                SqlConnection con = new SqlConnection(connectionString);

                try
                {
                    // ========================== \\ 打开
                    con.Open();

                }
                catch (Exception ex)
                {
                    // ========================== \\ 如果出错
                }
                finally
                {
                }

                SqlCommand cmd = new SqlCommand(sql, con);  // 执行Sql语句

                cmd.CommandType = CommandType.StoredProcedure;  // 

                SqlDataReader dr = cmd.ExecuteReader();
                return dr;

            }
       #endregion


    }