我有一個表2場「醫學生」和「Listino」,所以我只需要選擇Listino那裏的領域「醫學生」 = Medhi訪問數據庫選擇用VB.NET代碼
MEDICO LISTINO
---------------------
Medhi Gheller
Ashi Cadon
Pamdo Gheller
result:
Gheller
因爲Medhi有 'Listino' Gheller
下面的代碼
Public DBPath As String = "Listini.accdb"
Public StringaConn As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source= " & DBPath & ""
Public DBConn As New OleDbConnection(StringaConn)
Dim Medico As String = "Medhi"
DBConn.Open()
Dim DBCommAssociazione As OleDbCommand = DBConn.CreateCommand
DBCommAssociazione.CommandType = CommandType.Text
DBCommAssociazione.CommandText = "SELECT Listino FROM Associazioni WHERE Medico=Medhi"
Dim reader As OleDbDataReader
reader = DBCommAssociazione.ExecuteReader
While reader.Read()
Me.ListBox1.Items.Add(reader(0))
Me.ListBox1.Items.Add(reader(1))
End While
DBConn.Close()
謝謝。
Medico是一個文本字段。要在這一列搜索一個常數值,你需要把單引號放在常量值'Mehdi' – Steve