Having found the following post on datareaders Topic Posted On DaniWeb i have managed to successfully create a datareader in a class that updates a listbox on the calling form with entries retrieved from a SQL server database.

I was wondering if it is possible to achieve the same thing using a dataset?

My ultimate aim is to read a SQL table / view of information (ie customers), add this into a list box so that when i click on a specifc line in the list box i can then use that selected entry to do something further (ie click a line and then an edit button to edit that records details)

Here is the code im using for the data reader, any suggestions would be gratefully recieved.

Public Sub ReadCampaignRecords(ByVal strSQLServerConnectionString As String, ByVal strSqlCommandString As String)
        Dim objSqlConnection As New SqlConnection(strSQLServerConnectionString)
        Dim strSqlCommand As New SqlCommand(strSqlCommandString, objSqlConnection)

        If IsNothing(strSQLServerConnectionString) Then
            MessageBox.Show("Connection String Not Set")
        ElseIf IsNothing(strSqlCommandString) Then
            MessageBox.Show("No SQL Command Set")
        Else
            Try
                objSqlConnection.Open()

                Dim objDataReader As SqlDataReader = strSqlCommand.ExecuteReader()
                Dim strDataToView As String

                While objDataReader.Read()
                    Dim Number As Integer = CInt(objDataReader("Number"))
                    Dim StartDate As Date = CDate(objDataReader("StartDate"))
                    Dim EndDate As Date = CDate(objDataReader("EndDate"))

                    strDataToView = "Campaign  " & Number & "     Running From  = " & StartDate & " To " & EndDate

                    frmMainInterface.lstViewItemList.Items.Add(strDataToView)
                End While

                objDataReader.Close()
            Catch ex As Exception
                MessageBox.Show(ex.Message)

                objSqlConnection.Close()
                Exit Sub
            End Try
        End If
    End Sub
End Class

Edited 6 Years Ago by OldManStarting: n/a

Thanks Ranx.

That looks like it might be what im after, ill have a more detailed look later and post if it solves the issue.

Just a quick update, that page was exactly what i needed, i had previously created a dataset but could not work out the full commands to retrieve each row of data.

Thanks for the help.

This question has already been answered. Start a new discussion instead.