ronzarevele
New member
- Joined
- Feb 25, 2014
- Messages
- 1
- Programming Experience
- 1-3
Good day, i just want to ask a help from you with my problem in vb.net.. I have 1 listview in a form, in that form, it has also 1 textbox as txtsearch then a button to query. Whenever i type a string in a texbox then click the button, the data from the database will be displayed on the listview. My code is working. It can search from the database and display on the listview. Now my problem is, if i type the same string at a 3rd time, the data wont display on the listview. I dont know what's the problem on this. I search it on google but no luck. Here is my code:
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1
Dim strSQL As String = "SELECT * from tbl_all where itemCode= '" + txtsearch.Text + "' and DateBuy = '" + ComboBox1.SelectedItem.ToString + "' "
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost; Database=samal_db;" & _
"User ID=root; Password=;")
con.Open()
Dim cmd As MySqlCommand = New MySqlCommand(strSQL, con)
dr = cmd.ExecuteReader
ListView1.Items.Clear()
'If dr.HasRows Then
While dr.Read()
Dim LV2 As New ListViewItem
LV2.Text = dr("itemCode").ToString() 'Fills the first column of the row
LV2.SubItems.Add(dr("Description").ToString()) 'Fills the 1st subitem (2nd column)
LV2.SubItems.Add(dr("Qty").ToString()) 'Fills the 2nd subitem (3rd column)
LV2.SubItems.Add(FormatNumber(dr("Price").ToString(), 2, TriState.False, TriState.True, TriState.True)) 'Fills the 2nd subitem (4th column)
ListView1.Items.Add(LV2)
End While
dr.Close()
cmd.Dispose()
con.Close()
End Sub