WEB开发网
开发学院数据库Oracle 一个简单的oracle分页存储过程的实现和调用 阅读

一个简单的oracle分页存储过程的实现和调用

 2007-05-13 12:30:32 来源:WEB开发网   
核心提示: 在.net调用返回记录集的存储过程,需要用到datareader,一个简单的oracle分页存储过程的实现和调用(2),但是datareader不支持在datagrid中的分页,因此需要利用datagrid自定义分页功能

在.net调用返回记录集的存储过程,需要用到datareader,但是datareader不支持在datagrid中的分页,因此需要利用datagrid

自定义分页功能。

  Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
  Dim conn As New OracleClient.OracleConnection()
   Dim cmd As New OracleClient.OracleCommand()
   Dim dr As OracleClient.OracleDataReader
  Private Sub gridbind(ByVal pindex As Integer, ByVal psql As String, Optional ByVal psize As Integer = 10)
  conn.ConnectionString = "Password=gzdlgis;User ID=gzdlgis;Data Source=gzgis"
     cmd.Connection = conn
     cmd.CommandType = CommandType.StoredProcedure
     conn.Open()
  '------------------------------------------------------------------------------------
     cmd.CommandText = "DotNot.DotNetPageRecordsCount"
     '------------------------------------------------------------------------------------
     cmd.Parameters.Add("psqlcount", OracleType.VarChar).Value = psql
     cmd.Parameters.Add("prcount", OracleType.Number).Direction = ParameterDirection.Output
  cmd.ExecuteNonQuery()
  Me.DataGrid1.AllowPaging = True
     Me.DataGrid1.AllowCustomPaging = True
     Me.DataGrid1.PageSize = psize
     Me.DataGrid1.VirtualItemCount = cmd.Parameters("prcount").Value
  cmd.Parameters.Clear()
     '------------------------------------------------------------------------------------
     cmd.CommandText = "DotNot.DotNetPagination"
     '------------------------------------------------------------------------------------
     cmd.Parameters.Add("pindex", Data.OracleClient.OracleType.Number).Value = pindex
     cmd.Parameters.Add("psql", Data.OracleClient.OracleType.VarChar).Value = psql '"select rownum rn,t.* from cd_ssxl t"
     cmd.Parameters.Add("psize", Data.OracleClient.OracleType.Number).Value = psize
     cmd.Parameters.Add("v_cur", Data.OracleClient.OracleType.Cursor).Direction = ParameterDirection.Output
     cmd.Parameters.Add("pcount", Data.OracleClient.OracleType.Number).Direction = ParameterDirection.Output
  dr = cmd.ExecuteReader()
  Me.DataGrid1.DataSource = dr
     Me.DataGrid1.DataBind()
  dr.Close()
     conn.Close()
  Response.Write("总计页数 " & cmd.Parameters("pcount").Value)
   End Sub
  ----------------------------------------------------------------------------------------
  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     If Not Page.IsPostBack Then
       Dim psql As String = "select rownum rn,t.* from cd_ssxl t"
       gridbind(0, psql, 20)
      
     End If
  End Sub
  ---------------------------------------------------------------------------------------
  Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
     Dim psql As String = "select rownum rn,t.* from cd_ssxl t"
  Me.DataGrid1.CurrentPageIndex = e.NewPageIndex
     gridbind(e.NewPageIndex, psql, 20)
   End Sub

上一页  1 2 

Tags:一个 简单 oracle

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接