0

Greetings, Can someone please tell me on how to use this class?

Public Function GetDataFromStoredProcedure(ByVal spName As String) As DataTable
        Dim ds As New SqlDataAdapter
        Dim dt As New DataTable
        Dim cmd As New SqlCommand
        Dim con As New SqlConnection(_connectionString)

        Try
            _success = True
            con.Open()
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = spName
            cmd.Connection = con
            If _prmList.Count > 0 Then
                For Each prm As SqlParameter In _prmList
                    cmd.Parameters.Add(prm)
                Next
            End If
            ds.SelectCommand = cmd
            ds.Fill(dt)

            _message = "Employee Found!"

        Catch ex As Exception
            _success = False
            _message = ex.Message
            MsgBox(_message)
        Finally
            con.Dispose()
            cmd.Dispose()
            ds.Dispose()
            ds = Nothing
            con = Nothing
            cmd = Nothing
        End Try

        Return dt
    End Function

Cause i'm planning to use the class and the stored procedure instead of this code.

        Dim con As SqlConnection = New SqlConnection("Server = JAKE-PC ; Database = DentalDB ; trusted_connection=yes")
        con.Open()
        Dim dt As New DataTable
        Dim ds As New DataSet

        ds.Tables.Add(dt)

        Dim da As New SqlDataAdapter("SELECT p_ID, patientFname FROM tblPatient", con)
        da.Fill(dt)
        For Each dRow As DataRow In dt.Rows
            BetterListView1.Groups.Add(dRow("p_ID").ToString()).Items.Add((dRow("patientFname").ToString()))
        Next
1
Contributor
1
Reply
20
Views
3 Years
Discussion Span
Last Post by christan
0

Got the answer.

Solution:

     With dbComm
            For Each dRow As DataRow In .GetDataFromStoredProcedure("getPatientList").Rows
                BetterListView1.Groups.Add("Patient ID# " & dRow("p_ID").ToString).Items.Add(("Patient Name: " & dRow("patientFname").ToString()))
            Next
        End With
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.