其实很简单,但是写起来还是比较费力
Imports System.Data.OleDb
Public Class Form2
Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\project\office\test.accdb")
Sub bindtolist()
Dim cmd As New OleDbCommand("select b from maintab", conn)
Dim adp As New OleDbDataAdapter(cmd)
conn.Open()
Dim tb As New DataTable
adp.Fill(tb)
ListBox1.DataSource = tb
ListBox1.DisplayMember = "b"
conn.Close()
End Sub
Sub bindtotext(ByVal str As String)
Dim cmd As New OleDbCommand("SELECT a FROM MainTab WHERE (b = @s)", conn)
Dim adp As New OleDbDataAdapter(cmd)
cmd.Parameters.Add(New OleDbParameter("@s", OleDb.OleDbType.Char)).Value = str
conn.Open()
Dim td As New DataTable
adp.Fill(td)
TextBox1.Text = td.Rows(0).Item("a")
conn.Close()
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
bindtolist()
End Sub
Private Sub ListBox1_Click(sender As Object, e As EventArgs) Handles ListBox1.Click
Dim str As String = ListBox1.Text
bindtotext(str)
End Sub
End Class