如何将来自MS Access数据库的列表框中的选定项目显示到文本框?

时间:2017-03-12 05:21:28

标签: vb.net

我试图将产品的产品ID和价格从列表框显示到自己的文本框中,这些文本框名为' txtproductid'和&#t; txtprice'分别。 到目前为止,这是我的代码。没有错误出现和执行时。但是当我在列表框中点击我的产品时没有任何反应。它没有显示其ID和价格。我能错过什么?

Public Class shop
    Dim provider As String
    Dim datafile As String
    Dim connString As String
    Dim myConnection As OleDbConnection = New OleDbConnection
Private Sub listboxitems_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listboxitems.SelectedIndexChanged
    Dim lbconn As New OleDb.OleDbConnection("PROVIDER=Microsoft.ACE.Oledb.12.0; Data Source = C:\Users\USER PC\Desktop\orderDB1.accdb")
    Dim lbcmd As New OleDb.OleDbCommand("SELECT productid, product, price FROM productlog WHERE productid =' & listboxitems.Text & ' AND product ='" & listboxitems.Text & "' AND price =' & listboxitems.Text & '", lbconn)
    Dim lbreader As OleDbDataReader
    Try

    lbconn.Open()

    lbreader = lbcmd.ExecuteReader()
    While lbreader.Read
        txtproductid.Text = lbreader.GetInt32("productid")
        txtproduct.Text = lbreader.GetString("product")
        txtprice.Text = lbreader.GetInt32("price")


    End While

    Catch ex As Exception
    End Try

    lbconn.Close()

End Sub

编辑:我的访问数据库的屏幕截图

table

design view

0 个答案:

没有答案