| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 895 人关注过本帖
标题:三层模式 有些语句还不明白,哪个解析下不?谢谢
只看楼主 加入收藏
liaohongchu
Rank: 1
等 级:新手上路
帖 子:133
专家分:0
注 册:2008-4-25
结帖率:78.72%
收藏
已结贴  问题点数:4 回复次数:6 
三层模式 有些语句还不明白,哪个解析下不?谢谢
public Config Get_Config()
        {
            SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper();
            SqlDataReader rec=null;
            try
            {
                sqlHelper.RunProc("Get_Config", out rec);        这句是什么意思了呢?
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }
            Config config = new Config();
            while (rec.Read())
            {
                config.About = rec["About"].ToString();
                config.Contact = rec["Contact"].ToString();
            }
            return config;   这句是返回,是不是config.About 就可以调整内容了呢?
搜索更多相关主题的帖子: 解析 模式 语句 
2010-03-12 16:31
传统大侠
Rank: 1
来 自:湖南
等 级:新手上路
威 望:1
帖 子:3
专家分:0
注 册:2010-3-12
收藏
得分:0 
我给你找一个我整理的数据操作的所有类吧,里面关于数据的所有操作应该都有,前面必须添加config应用
public static class DBHelper
    {

        private static SqlConnection connection;

        public static SqlConnection Connection
        {
            get
            {
                string connectionString =
                   ConfigurationManager.ConnectionStrings["WebSiteDB"].ConnectionString;//记得在config文件里设置
                if (connection == null)
                {
                    connection = new SqlConnection(connectionString);
                    
                    connection.Open();
                }
                else if (connection.State == System.Data.ConnectionState.Closed)
                {
                    connection.Open();
                }
                else if (connection.State == System.Data.ConnectionState.Broken)
                {
                    connection.Close();
                    connection.Open();
                }
                return connection;
            }
        }

        public static int ExecuteCommand(string safeSql)
        {
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            int result = cmd.ExecuteNonQuery();
            return result;
        }

        public static int ExecuteCommand(string sql, params SqlParameter[] values)
        {
            SqlCommand cmd = new SqlCommand(sql, Connection);
            cmd.Parameters.AddRange(values);
            return cmd.ExecuteNonQuery();
        }

        public static int GetScalar(string safeSql)
        {
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            return result;
        }

        public static int GetScalar(params SqlParameter[] values)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = Connection;
             = "Pro_InsertOrder";
             = CommandType.StoredProcedure;
            cmd.Parameters.AddRange(values);
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            return result;
        }

        public static int GetScalar(string sql, params SqlParameter[] values)
        {
            SqlCommand cmd = new SqlCommand(sql, Connection);
            cmd.Parameters.AddRange(values);
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            return result;
        }

        public static SqlDataReader GetReader(string safeSql)
        {
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            SqlDataReader reader = cmd.ExecuteReader();
            return reader;
        }

        public static SqlDataReader GetReader(string sql, params SqlParameter[] values)
        {
            SqlCommand cmd = new SqlCommand(sql, Connection);
            cmd.Parameters.AddRange(values);
            SqlDataReader reader = cmd.ExecuteReader();
           
            return reader;
        }

        public static DataTable GetDataSet(string safeSql)
        {
            DataSet ds = new DataSet();
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            return ds.Tables[0];
            
        }

        public static DataTable GetDataSet(string sql, params SqlParameter[] values)
        {
            DataSet ds = new DataSet();
            SqlCommand cmd = new SqlCommand(sql, Connection);
            cmd.Parameters.AddRange(values);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            return ds.Tables[0];
        }

        
    }
}

好好学习,天天向上
2010-03-12 17:20
bf_2008
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-3-12
收藏
得分:0 
就是使用中间层
--------------------个人签名
http://www.
2010-03-12 17:27
misswang
Rank: 8Rank: 8
来 自:湖北荆州
等 级:贵宾
威 望:15
帖 子:265
专家分:720
注 册:2010-3-11
收藏
得分:4 
sqlHelper.RunProc("Get_Config", out rec);
估计是调用存储过程

misswp2010@
wangping103@
2010-03-12 21:06
misswang
Rank: 8Rank: 8
来 自:湖北荆州
等 级:贵宾
威 望:15
帖 子:265
专家分:720
注 册:2010-3-11
收藏
得分:0 
还是带输出参数的存储过程

misswp2010@
wangping103@
2010-03-12 21:07
liaohongchu
Rank: 1
等 级:新手上路
帖 子:133
专家分:0
注 册:2008-4-25
收藏
得分:0 
谢谢 是 存储过程 。
2010-03-13 09:25
zhuyunshen
Rank: 6Rank: 6
等 级:侠之大者
威 望:2
帖 子:212
专家分:455
注 册:2009-11-22
收藏
得分:0 
sqlHelper.RunProc("Get_Config", out rec);
调用存储过程
2010-03-13 09:55
快速回复:三层模式 有些语句还不明白,哪个解析下不?谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018941 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved