首页 新闻 会员 周边 捐助

请问这个怎么理解?

0
悬赏园豆:10 [已关闭问题]
<p class="ab"><span lang="EN-US">下面是ObjectDataSource绑定到的业务层的两个方法,其中ObjectDataSource控件中SelectMethod="LoadByCountry",参数为country.我想知道下面有两个重载的方法,ObjectDataSource怎么知道用哪个方法?还有就是为什么要重载?谢谢!</span></p> <p class="ab"><span lang="EN-US">public static CustomerCollection LoadByCountry(string country)</span></p> <p class="ab"><span lang="EN-US">{</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp; return LoadByCountry(country, -1, 0);</span></p> <p class="ab"><span lang="EN-US">}</span></p> <p class="ab"><span lang="EN-US">public static CustomerCollection LoadByCountry(string country,</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int totalRows, int firstRow)</span></p> <p class="ab"><span lang="EN-US">{</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp; CustomerCollection coll = new CustomerCollection();</span></p> <p class="ab"><span lang="EN-US">&nbsp;</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp; using (SqlConnection conn = new SqlConnection(ConnectionString))</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp; {</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmd;</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd = new SqlCommand(CustomerCommands.cmdLoadByCountry, conn);</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.Parameters.AddWithValue("@country", country);</span></p> <p class="ab"><span lang="EN-US">&nbsp;</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Open();</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataReader reader = cmd.ExecuteReader();</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelperMethods.FillCustomerList(coll, reader, totalRows, firstRow);</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reader.Close();</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Close();</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp; }</span></p> <p class="ab"><span lang="EN-US">&nbsp;</span></p> <p class="ab"><span lang="EN-US">&nbsp;&nbsp;&nbsp; return coll;</span></p> <p class="ab"><span lang="EN-US">} </span></p>
爱上编程的主页 爱上编程 | 初学一级 | 园豆:55
提问于:2008-11-12 21:11
< >
分享
其他回答(2)
0

 1、为什么要重载:估计是为了分页

2、ObjectDataSource会根据参数的个数去找相应的方法,对于SelectMethod, InputParameters会根据SelectParameters生成,分页情况下,还会有startRowIndex和maximumRows参数

要有好的心情 | 园豆:502 (小虾三级) | 2008-11-12 22:02
0

补充:

如果是SelectMethod="LoadByCountry",参数为country,那么将调用第一个方法

至于是否用于分页,比较怀疑,需要看一下HelperMethods.FillCustomerList这个方法才能确定

感觉这个写法比较奇怪,两个重载基本拥有相同的效率,如果是为了分页,可以看出来对于从数据库读取数据这一操作,两个重载是一样的,没有效率上的任何提升,所以怀疑并不是为了分页

丁学 | 园豆:18730 (专家六级) | 2008-11-13 07:41
0

我觉得应该是为了分页 不过这样的分页效率确实不是很高

张荣华 | 园豆:2020 (老鸟四级) | 2008-11-13 09:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册