Last post May 17, 2012 03:10 PM by bullpit
May 17, 2012 02:49 PM|Lord Moldybutt|LINK
The code below works. I have a Label that isn't showing duplicate records and I want it to. Currently, it only show one record. Now I know that I can do this with GridView, DataList and those jokers but I want to see if I can do it with Label. Any help?
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles SearchButton.Click
Dim ConnString As String = BaseClass.GetConnString
Dim USQL As String = _
"SELECT NameUsers.LastName, NameUsers.Last4 FROM(NameUsers) WHERE (((NameUsers.Last4)='" & SearchTB.Text & "'));"
'SearchTB is a TextBox just FYI
Using conn As New OleDbConnection(ConnString)
Using cmd As New OleDbCommand(USQL, conn)
cmd.CommandType = Data.CommandType.Text
Using reader As OleDbDataReader = cmd.ExecuteReader()
If Not reader.HasRows Then
ResultsLabel.Text = "No records!"
ResultsLabel.Text = reader("LastName").ToString
SearchTB.Text = ""
May 17, 2012 02:56 PM|bullpit|LINK
Change ResultsLabel.Text = reader("LastName").ToString to ResultsLabel.Text += reader("LastName").ToString.
You are assigning the value to the Label.Text property in a loop, so it will rewrite Label.Text everytime it goes into that loop, effectively displaying just the last value from the loop.
May 17, 2012 03:02 PM|Lord Moldybutt|LINK
bullpit... I totally forgot about the += operator... And that is why you are an ALL-Star!!!
God Bless You!!!
May 17, 2012 03:10 PM|bullpit|LINK
Thank you and you too.