Want to Disply Multiple Rows in Text Box from Excel Workbook using VB.Net

I am writing a desktop application using VB.Net and an Excel Workbook as the database. I can display one row easily using the code below.  How do I display all rows from the workbook that have the same date? Thanks in advance.

Here is the code I am using. I have attached the Excel File.

Private m_sConn1 As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
               "Data Source=c:\computers\vb project\Sweetheart\mydates.xlsx;" & _
               "Extended Properties=""Excel 12.0;HDR=YES"""


    Private Sub cmdFind_Click(sender As Object, e As EventArgs) Handles cmdFind.Click
        Dim cn As New System.Data.OleDb.OleDbConnection(m_sConn1)
        Dim appt, apdt, amessage As String
        Dim format = "MM,dd,yyyy"

        Dim begindt As Date = dtpBegin.Value.ToString(format)
        Dim enddt As Date = dtpEndDt.Value.ToString(format)
        Dim cm As New OleDbDataAdapter("Select * From [Sheet1$] where Date =  '" & begindt & "'", cn)
       
        Dim ds As DataSet = New DataSet()


        cn.Open()
        cm.Fill(ds)
        If TextBox1.Text = "" Then
            Debug.WriteLine(vbCrLf & "Bills:" & vbCrLf & "=============")
            Dim dr As DataRow


            For Each dr In ds.Tables(0).Rows 'Show results in output window

                'Debug.WriteLine(System.String.Format("{0,-15}{1, -6}{2}", _
                '       dr("Event"), dr("Date"), dr("Message")))

            Next
            appt = dr("Event")
            apdt = dr("Date")
            amessage = dr("Message")
            TextBox1.Text = "Category      " & "Date             " & "Info  " & vbCrLf & vbCrLf & appt & "    " & apdt & "    " & amessage
        End If





    End Sub



mydates.xlsx
waynerayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I think you'd be better off using a DataGridView, or a ListView, instead of a Textbox to display multi-row data. If you use a DGV you can simply use this code to fill it:

YourDataGridView.Datasource = ds.Tables(0)

If you MUST show it in a Textbox, make sure the Textbox is set to Multiline, and then do this:

Dim msg As String = "Category      " & "Date             " & "Info  "
For Each dr In ds.Tables(0).Rows 'Show results in output window
    msg = msg & Environment.NewLine & "dr("Event"), dr("Date"), dr("Message")))
Next

YourTextbox.TExt = msg

You will almost certainly run into spacing and alignment issues, however, since a Textbox is not intended to show columnar data.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
waynerayAuthor Commented:
Thanks Scott. I know I could use a datagrid and I have already experienced the spacing issues. I haven't tried a listview. Thanks again.
0
waynerayAuthor Commented:
Scott's solution helped me overcome a block in the road. His response offered me more than I asked for and I appreciate his answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.