用datatable存儲oracle輸出值


         ' GetDBConn()自定義的包含connectstring的oracle db連接
         Dim  conn  As  OracleConnection  =  GetDBConn()
        
        
' 判斷是否打開
         If  conn.State  <>  ConnectionState.Open  Then
             
Return   Nothing
        
End   If
        
       
'  參數
         Dim  para1  As   New  OracleParameter( " fields " , OracleDbType.Varchar2, ParameterDirection.Input)
        para1.Value 
=  fields
        
Dim  para2  As   New  OracleParameter( " viewname " , OracleDbType.Varchar2, ParameterDirection.Input)
        para2.Value 
=  viewname
        
Dim  para3  As   New  OracleParameter( " whereclause " , OracleDbType.Varchar2, ParameterDirection.Input)
        para3.Value 
=  whereclause
        
Dim  para4  As   New  OracleParameter( " orderby " , OracleDbType.Varchar2, ParameterDirection.Input)
        para4.Value 
=  orderby

        
Dim  para5  As   New  OracleParameter( " userid " , OracleDbType.Int32, ParameterDirection.Input)
        para5.Value 
=  intWorkID

       
' 選擇command類型為StoredProcedure以及Procedure名
         Dim   command   As   New  OracleCommand
        
command .Connection  =  conn
        
command .CommandText  =   " pkgcursor.getcur "
        
command .CommandType  =  CommandType.StoredProcedure
      
       
' 參數輸入
         command .Parameters.Add(para1)
        
command .Parameters.Add(para2)
        
command .Parameters.Add(para3)
        
command .Parameters.Add(para4)
        
command .Parameters.Add(para5)
       
' outpara是procedure內定義的輸出函數
         Dim  outpara  As   New  OracleParameter( " cur " , OracleDbType.RefCursor,  Data.ParameterDirection.Output)
        
command .Parameters.Add(outpara)
       
       
' 接受輸出值
         Dim  dr  As  OracleDataReader
        dr 
=   command .ExecuteReader()
        
' 用datatable裝輸出值
         Dim  dt  As   New  DataTable
        dt.Load(dr)
        
Return  dt
        
   

 

你可能感兴趣的:(Datatable)