Developing Your Own SQL Server Based Data Access Helper using COM+ and VB.NET - Retrieving more than one row
(Page 4 of 7 )
The following template will help you retrieve more than one row in the form of a data table.
PublicFunction getDataTable(ByVal sqlSELECT As String) As
System.Data.DataTable
Dim Conn As SqlConnection
Dim da As SqlDataAdapter
Try
Conn = New SqlConnection(_ConnectionString)
Dim dt As New DataTable
da = New SqlDataAdapter(sqlSELECT, Conn)
da.Fill(dt)
da.Dispose()
Return dt
Catch ex As Exception
Try
da.Dispose()
Catch e As Exception
'do nothing...if still error persists
End Try
Throw New Exception(ex.Message & ". SQL Statement: "
& sqlSELECT)
End Try
End Function
You can also retrieve a “DataView” object as follows:
PublicFunction getDataView(ByVal sqlSELECT As String) As System.Data.DataView
Return New DataView(getDataTable(sqlSELECT))
End Function
Next: Adding a few more helper methods >>
More MS SQL Server Articles
More By Jagadish Chaterjee