| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1214 人关注过本帖
标题:command.ExecuteReader(CommandBehavior.CloseConnection))是什么意思了?
只看楼主 加入收藏
liaohongchu
Rank: 1
等 级:新手上路
帖 子:133
专家分:0
注 册:2008-4-25
结帖率:78.72%
收藏
已结贴  问题点数:20 回复次数:4 
command.ExecuteReader(CommandBehavior.CloseConnection))是什么意思了?
public override ProductPropertyCollection GetProductPropertySet(string sql, int pageIndex, int pageSize, bool includePageIndex, bool returnFullThread)
        {
            using (SqlConnection myConnection = new SqlConnection(this.connectionString))
            {
                using (SqlCommand command = new SqlCommand("dbo.[RS_Get_ProductPropertySet]", myConnection))
                {
                     = CommandType.StoredProcedure;

                    command.Parameters.Add("@PageIndex", SqlDbType.Int, 4).Value = pageIndex;
                    command.Parameters.Add("@PageSize", SqlDbType.Int, 4).Value = pageSize;
                    command.Parameters.Add("@sqlPopulate", SqlDbType.NText).Value = sql;
                    command.Parameters.Add("@IncludePageIndex", SqlDbType.Bit).Value = includePageIndex;
                    command.Parameters.Add("@ReturnFullThread", SqlDbType.Bit).Value = returnFullThread;
                    command.Parameters.Add("@TotalRecords", SqlDbType.Int).Direction = ParameterDirection.Output;

                    ProductPropertyCollection productpropertySet = new ProductPropertyCollection();

                    // Execute the command
                    myConnection.Open();
                    using (SqlDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        while (dr.Read())
                        {
                            productpropertySet.Add(PopulateProductPropertyEntryFromIDataReader(dr));
                        }

                        if (includePageIndex)
                        {
                            dr.NextResult();
                            while (dr.Read())
                                productpropertySet.PageIndex.Add(dr[0], dr[1]);
                        }

                        dr.Close();
                        myConnection.Close();
                        productpropertySet.TotalRecords = (int)command.Parameters["@TotalRecords"].Value;
                    }

                    return productpropertySet;
                }
            }
        }


SqlDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection))

CommandBehavior.CloseConnection  这个找不到哪里定义的? 高手帮忙解答下了? 谢谢!
搜索更多相关主题的帖子: command 
2010-04-07 16:47
yms123
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:20 
这段代码是在调用一个SQL Server的存储过程,这个存储过程是用来读取数据库中的数据进行分页的,用存储过程来看估计数据库中存有的数据很多这时就得需要使用存储过程来读取了,CommandBehavior.CloseConnection 这个不用解释了吧?刚才说过了静态类成员是不需要实例化(也就是定义)的。
而且楼主的基础知识都没学过吗?
2010-04-07 17:00
liaohongchu
Rank: 1
等 级:新手上路
帖 子:133
专家分:0
注 册:2008-4-25
收藏
得分:0 
谢谢 我半路出家, 没有那么专。 工作要看多点。
2010-04-07 23:01
ssq1984
Rank: 1
等 级:新手上路
帖 子:3
专家分:2
注 册:2010-4-8
收藏
得分:0 
CommandBehavior.CloseConnection是在关闭Connection的时候也关闭SqlDataReader吧
2010-04-08 13:20
快速回复:command.ExecuteReader(CommandBehavior.CloseConnection))是什么意思 ...
数据加载中...
 
   



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

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