Public Function GetData(ByVal sSQL As String, Optional ByRef ErrorString As String = "") As DataSet
Dim myDS As New DataSet
Dim myDA As New SqlDataAdapter
Dim cmd As SqlCommand 'sql command
cmd = New SqlCommand
cmd.Connection = ConnectionOpen()
cmd.CommandTimeout = 0
'-------------------------------------------------------------------
' If a transaction object exists hook it up
'-------------------------------------------------------------------
'If Not IsNothing(mTransaction) Then
' cmd.Transaction = mTransaction
'End If
cmd.CommandText = sSQL
myDA = New SqlDataAdapter(cmd)
myDS = New DataSet
Try
myDA.Fill(myDS)
Catch ex As Exception
ErrorString = Err.Number & ": " & Err.Description
End Try
Return myDS
myDA = Nothing
myDS = Nothing
End Function
Here's a typical call to the above function:
retRow = oData.GetData("EXEC " & StoredProc & " '" & FileName & "', '" & ClientCode & "','" & ConfigurationSettings.AppSettings("CentaurusUserID") & "'").Tables(0).Rows(0)
What really bothers me about this code is that the error message is optional. In what situations would you not want to know that an error has occurred?
No comments:
Post a Comment