应用该存储过程

private DataSet GetPageData(uint pageSize, uint pageIndex)     
  {          
   string strConn = System.Configuration.ConfigurationSettings.AppSettings["ConnString1"];                    
   SqlConnection conn = new SqlConnection(strConn);          
   conn.Open();           
   SqlCommand command = new SqlCommand("GetCustomDataPage",conn);
   //第一个参数为存储过程名         
   command.CommandType = CommandType.StoredProcedure;  
   //声明命令类型为存储过程          
   command.Parameters.Add("@pageSize",SqlDbType.Int);         
   command.Parameters["@pageSize"].Value = pageSize;         
   command.Parameters.Add("@pageIndex",SqlDbType.Int);          
   command.Parameters["@pageIndex"].Value = pageIndex;          
   command.Parameters.Add("@pageCount",SqlDbType.Int);          
   command.Parameters["@pageCount"].Value = pageCount;           
   command.Parameters["@pageCount"].Direction = ParameterDirection.Output;
   //存储过程中的输出参数           
   command.Parameters.Add("@recordCount",SqlDbType.Int);          
   command.Parameters["@recordCount"].Value = recordCount;           
   command.Parameters["@recordCount"].Direction = ParameterDirection.Output;
   //存储过程中的输出参数            
   SqlDataAdapter adapter = new SqlDataAdapter(command);         
   DataSet ds = new DataSet();          
   adapter.Fill(ds);                     
   //获得输出参数值         
   pageCount = Convert.ToUInt32(command.Parameters["@pageCount"].Value);      
   recordCount = Convert.ToUInt32(command.Parameters["@recordCount"].Value);     
   conn.Close();         
   return ds;        
  }       

//绑定数据到DataGrid中      
  private void BindDataGrid()     
  {        
   DataSet ds = GetPageData((uint)dgProduct.PageSize,(uint)dgProduct.CurrentPageIndex); 
   dgProduct.VirtualItemCount = (int)recordCount;           
   dgProduct.DataSource = ds;         
   dgProduct.DataBind();     
  }       

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章