/ Published in: VB.NET
Ejecutar sp retornando un datatable, Ejecutar sp retornando un dataset, Ejecutar sp Update retornando los registros actualizados
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
''' <summary> ''' Regresa un dataset mediante parametro de SP a ejecutar regresa DataTable ''' </summary> ''' <param name="spExecute"> Llamada a sp con parametros SQLSERVER</param> ''' <returns></returns> ''' <remarks></remarks> Function executeSPdt(ByVal spExecute As String) As DataTable Dim da As SqlDataAdapter = Nothing Dim res As New DataTable Try Me.cmd = New SqlCommand(spExecute, conecctedDB()) Me.da = New SqlDataAdapter(Me.cmd) Me.da.Fill(res) Catch ex As SqlException Throw New System.Exception("Error de conexion a la basde de datos: executeSP", ex) Finally If Not (Me.cmd Is Nothing) Then Me.cmd.Dispose() If Not (Me.da Is Nothing) Then Me.da.Dispose() End Try 'Valor resultado Return res End Function ''' <summary> ''' Regresa un dataset mediante parametro de SP a ejecutar regresa DataSet ''' </summary> ''' <param name="spExecute"> Llamada a sp con parametros SQLSERVER</param> ''' <returns></returns> ''' <remarks></remarks> Function executeSPds(ByVal spExecute As String) As DataSet Dim da As SqlDataAdapter = Nothing Dim res As New DataSet Try Me.cmd = New SqlCommand(spExecute, conecctedDB()) Me.da = New SqlDataAdapter(Me.cmd) Me.da.Fill(res) Catch ex As SqlException Throw New System.Exception("Error de conexion a la basde de datos: executeSP", ex) Finally If Not (Me.cmd Is Nothing) Then Me.cmd.Dispose() If Not (Me.da Is Nothing) Then Me.da.Dispose() End Try 'Valor resultado Return res End Function ''' <summary> ''' Ejecuta SP UPDATE y regresa los RowsActualizados ''' </summary> ''' <param name="spExecute"></param> ''' <returns></returns> ''' <remarks></remarks> Function executeSPGetRowsAffected(ByVal spExecute As String) As System.Int64 Dim rowsAffected As Integer = 0 Try Me.cmd = New SqlCommand(spExecute, conecctedDB()) 'Executa el comando y regresa rows afectados rowsAffected = Me.cmd.ExecuteNonQuery() Return rowsAffected Catch ex As SqlException Throw New System.Exception("Error de conexion a la basde de datos executeSPGetRowsAffected - " + spExecute, ex) Finally If Not (Me.cmd Is Nothing) Then Me.cmd.Dispose() If Not (Me.da Is Nothing) Then Me.da.Dispose() End Try Return rowsAffected End Function