hye guys..here is the problem..how to use the item in the listview in order to retrieve data from database?
i have code that display 4 digit in every line in listview item..

 Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click


        Dim xmtBuf() As Byte = {&HAA, &H0, &H4, &H10, &H6, &H0, &H0, &H12, &HBB}
        comport.Write(xmtBuf, 0, xmtBuf.Length)
        Thread.Sleep(250)
        'Comport.ReadByte()
        UPdateTextBox()
    End Sub
    Public Sub UPdateTextBox()
        If comport.IsOpen Then
            Dim bytes As Integer = comport.BytesToRead
            Dim buffer(bytes) As Byte
            Dim tagid As String
            'Dim i As Integer
            '\\ to read data from read buffer
            comport.Read(buffer, 0, bytes)
            If buffer.Length > 1 Then
                tagid = ByteArrayToHexString(buffer)
                'If txtSearch.TextLength = 16 Then
                txtSearch.Text = tagid

                Dim tags As String = tagid.ToString
                tags = tags.Substring(0, 4)
                Dim test As String = "qweqwe1212adfaf2433adfa1133"
                Dim allrfids As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(tagid, "\d{4}(01)*")
                For Each rfid As System.Text.RegularExpressions.Match In allrfids
                    tags = rfid.ToString
                    tags = tags.Substring(0, 4)
                    'TextBox3.Text = tags
                    'MsgBox("TAG: " & tags)
                    ListView1.Items.Add(tags)
               next

some of the item in the listview have the same value with item in database..what i want is for every match item, the data from database will display automatically.

Recommended Answers

All 3 Replies

Instead of inserting the tags value directly into the list view, you should create a list view Item with the value of tags.

Using the tags field, you need to ceate a select command to the daabase to find if the record exists.

In order the command to the database can be executed, you need to hava a connection to the dabase, that must be in open state before executing the command.

To retrieve the info from the database, you can use a data reader, from the execute reader function of the command.

Using a try catch structure, you must verify id the data reader has rows, to be certain that you find the tags value in the database.

If has rows, then you must force a read to retrieve the first row, that should contain the related info, and add subitems to the list view item with the value of the corresponding returned field.

If has no rows, then you must add the right number of subitems to the list view item with an empty string.

Catch any errors and finally you must close the data reader.

Then you can add the list view item to the list view.

Hope this helps

thank you lolafuertes for rply..what do you mean by create a list view item with value tags instead of put the tags value directly to list view?

Instead of inserting your value in the tags, why dont you put it in a textbox and then turn it to visible = false.

Assumming your listview looks like this.

 Number     First Name    Last Name

   1         Mike          Shinoda
   2        Anderson       Silva
   3         Steve          Jobs

Now you have 3 items inside your listview..

Double Click your listview and add the ff.

  Dim index As ListView.CheckedIndexCollection = ListView1.CheckedIndices

  Dim i As Integer = 0

  For Each i In index

  Textbox1.text = Listview1.items(0).subitems(0).text    

  Next

Note:
Use .subitems(0).text if you want to get the Number
Use .subitems(1).text if you want to get the First Name
Use .subitems(2).text if you want to get the Last Name

The code only works every time you select an item in the listview or just by clicking an item in the listview.

If you want to test if the code really works set your textbox properties to visible true so that you will see every time the value change.

hope it helps... please marked solve...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.