Posted By

systemergon on 02/05/16


Tagged

update datatable dataset disponse origen desconcetado


Versions (?)

Trabajando SP con DataTable , Dataset y Update origen desconectado


 / Published in: VB.NET
 

Ejecutar sp retornando un datatable, Ejecutar sp retornando un dataset, Ejecutar sp Update retornando los registros actualizados

  1. ''' <summary>
  2. ''' Regresa un dataset mediante parametro de SP a ejecutar regresa DataTable
  3. ''' </summary>
  4. ''' <param name="spExecute"> Llamada a sp con parametros SQLSERVER</param>
  5. ''' <returns></returns>
  6. ''' <remarks></remarks>
  7. Function executeSPdt(ByVal spExecute As String) As DataTable
  8. Dim da As SqlDataAdapter = Nothing
  9. Dim res As New DataTable
  10. Try
  11. Me.cmd = New SqlCommand(spExecute, conecctedDB())
  12. Me.da = New SqlDataAdapter(Me.cmd)
  13. Me.da.Fill(res)
  14. Me.con.Close()
  15. Catch ex As SqlException
  16. Throw New System.Exception("Error de conexion a la basde de datos: executeSP", ex)
  17. Finally
  18. If Not (Me.cmd Is Nothing) Then Me.cmd.Dispose()
  19. If Not (Me.da Is Nothing) Then Me.da.Dispose()
  20. End Try
  21. 'Valor resultado
  22. Return res
  23. End Function
  24.  
  25.  
  26.  
  27.  
  28. ''' <summary>
  29. ''' Regresa un dataset mediante parametro de SP a ejecutar regresa DataSet
  30. ''' </summary>
  31. ''' <param name="spExecute"> Llamada a sp con parametros SQLSERVER</param>
  32. ''' <returns></returns>
  33. ''' <remarks></remarks>
  34.  
  35. Function executeSPds(ByVal spExecute As String) As DataSet
  36. Dim da As SqlDataAdapter = Nothing
  37. Dim res As New DataSet
  38. Try
  39. Me.cmd = New SqlCommand(spExecute, conecctedDB())
  40. Me.da = New SqlDataAdapter(Me.cmd)
  41. Me.da.Fill(res)
  42. Me.con.Close()
  43. Catch ex As SqlException
  44. Throw New System.Exception("Error de conexion a la basde de datos: executeSP", ex)
  45. Finally
  46. If Not (Me.cmd Is Nothing) Then Me.cmd.Dispose()
  47. If Not (Me.da Is Nothing) Then Me.da.Dispose()
  48. End Try
  49. 'Valor resultado
  50. Return res
  51. End Function
  52.  
  53.  
  54. ''' <summary>
  55. ''' Ejecuta SP UPDATE y regresa los RowsActualizados
  56. ''' </summary>
  57. ''' <param name="spExecute"></param>
  58. ''' <returns></returns>
  59. ''' <remarks></remarks>
  60. Function executeSPGetRowsAffected(ByVal spExecute As String) As System.Int64
  61. Dim rowsAffected As Integer = 0
  62. Try
  63. Me.cmd = New SqlCommand(spExecute, conecctedDB())
  64.  
  65. 'Executa el comando y regresa rows afectados
  66. rowsAffected = Me.cmd.ExecuteNonQuery()
  67. Return rowsAffected
  68. Catch ex As SqlException
  69. Throw New System.Exception("Error de conexion a la basde de datos executeSPGetRowsAffected - " + spExecute, ex)
  70. Finally
  71. If Not (Me.cmd Is Nothing) Then Me.cmd.Dispose()
  72. If Not (Me.da Is Nothing) Then Me.da.Dispose()
  73. If Not (Me.con Is Nothing) Then Me.con.Close()
  74. End Try
  75.  
  76. Return rowsAffected
  77. End Function

Report this snippet  

You need to login to post a comment.