應用該存儲過程

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();     
  }       

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