vb.net在access数据库中搜索

时间:2017-07-03 09:14:53

标签: database vb.net

我有一个基本问题。我有一个访问数据库,其中我有一个包含2列的List2。我有一个输入框,我扫描条形码编号,我想在第1列(名称标题 - Zak)中搜索此条形码编号,如果在列中找到此条形码然后显示我在同一行的第2列(名称标题Cisl)值条码。我有一部分代码,我不知道如何继续。谢谢你的帮助

Private Sub PictureBox12_Click(sender As Object, e As EventArgs) Handles PictureBox12.Click
    Dim barcode As String = Nothing
    Dim foundRows() As Data.DataRow

    barcode = InputBox("Naskenujte čárový kód ||||||||||||||||||||||||||||||||||||")
    If Len(Trim(barcode)) = 0 Then Exit Sub   'Pressed cancel

    'Vytvoreni dotazu

    foundRows = SdfDataSet.Tables("List2").Select("[Zak] = '" & barcode & "'")


    If foundRows IsNot Nothing Then
        MsgBox("Nenalezeno")
    Else
        MsgBox("Zákaznické číslo: " & barcode & foundRows(0)("Cisl"))
    End If

End Sub

这是图像数据库https://s4.postimg.org/8qulca9e5/source.png

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,

就是这样:

 'Get the Row with the barcode.
 Dim foundRows() As Data.DataRow
 foundRows = DataSet1.Tables("List1").Select("[Zak] = '" & barcode & "'")

If foundRow IsNot Nothing Then
    'If not Found do something here or not.    
Else
   'If found output the first found rows Column2
    MsgBox("Zákaznické číslo: " & barcode & foundRow(0)("Column2"))
End If

注意:将 Column2 替换为列名。

相关问题