I can't figure out what I am doing wrong. I am trying to read multiple rows of data into the same textbox. I am using a Datareader. let me explain what I am trying to do.
I am creating a customer notes/comments section in my application. I want to store notes/comments about customer service conversation. I am storing them with the date & time the comment was added. This is stored in a Access database. I want to retrieve the data and display it on a winform. I have choosen a multi-line textbox. I can get the data to display in the textbox but it only displays the last record of a customer that has multiple records.
I'm not sure if it is possible, is there a better way or what am I missing.
What I have tried:
CustomerNotes table:
CusNumber Date/Time Comment
1350 3/29/2019 8:52:42 AM Customer is wanting a refund.
1376 8/23/2018 10:52:42 PM They were not happy with the product.
1350 4/4/2019 2:43:11 PM We issued a refund.
Textbox result that I want:
3/29/2019 8:52:42 AM
Customer is wanting a refund.
4/4/2019 2:43:11 PM
We issued a refund.
My code:
Try
Dim command = New OleDb.OleDbCommand
Call connection()
Dim drCustomerNotes As OleDbDataReader = Nothing
With cm
.Connection = con
.CommandText = "SELECT * FROM tblCusNotes WHERE fldCusNotesAcctNo = @CusAcctNo"
Try
.Parameters.Clear()
.Parameters.Add("@CusAcctNo", OleDbType.Integer).Value = tbCusAcctNo.Text
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
drCustomerNotes = .ExecuteReader
End With
While drCustomerNotes.Read()
CusNotesTemp = drCustomerNotes("fldCusNotesDateEntered").ToString
CusNotesTemp = CusNotesTemp + vbCrLf + drCustomerNotes("fldCusNotesText").ToString + vbCrLf
tbCusNotes.Text = CusNotesTemp
CusNotesfound = True
End While
If CusNotesfound = False Then MsgBox("Cus Notes Info Not Found.", MsgBoxStyle.Information)
drCustomerNotes.Close()
Textbox result that I get with the above code:
4/4/2019 2:43:11 PM
We issued a refund.