datalist分页(cj168.DataAccess.MagsDB中的2个方法)

80酷酷网    80kuku.com

  access|分页public ICollection GetSearchResult(String txtSearch, int StartIndex, int PageSize)
        {
            
            SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlDataAdapter myCommand = new SqlDataAdapter("GetSearchResult", myConnection);
            
            myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
            
            SqlParameter parameterTxtSearch = new SqlParameter("txtSearch", SqlDbType.VarChar, 255);
            parameterTxtSearch.Value = txtSearch;
            myCommand.SelectCommand.Parameters.Add(parameterTxtSearch);

            DataSet myDataSet = new DataSet();
        
            myCommand.Fill(myDataSet, StartIndex, PageSize, "SearchResult");
            
            return myDataSet.Tables["SearchResult"].DefaultView;

        }


        public int GetSearchResultCount(String txtSearch)
        {
            int intCount ;
            intCount = 0;
            

            SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand myCommand = new SqlCommand("GetSearchResultCount", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;

            SqlParameter parameterTxtSearch = new SqlParameter("txtSearch", SqlDbType.VarChar, 255);
            parameterTxtSearch.Value = txtSearch;
            myCommand.Parameters.Add(parameterTxtSearch);

            myConnection.Open();
            SqlDataReader dr =myCommand.ExecuteReader();
            
            if(dr.Read())
            {
                intCount = Int32.Parse(dr["co"].ToString());
            }
            else
            {
                intCount = 0;
            }
            
            dr.Close();
            return intCount;

        }

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: