如何将combobox控件和Listbox 关联到数据库??
本人想通过combobox 控件中选择数据库中的系列代码,让Listbox中显示一一对应的规格代码,现无法在listbox中显示结果,如有高手知道,请解答下具体操作步骤,或者联系QQ408435325谢谢
祥图如下:
[此贴子已经被作者于2007-10-26 13:49:06编辑过]
listbox關聯數據庫
Dim strtemp01 As String
Dim datemp01 As SqlClient.SqlDataAdapter
Dim dstemp01 As DataSet
Dim rw01 As DataRow
Dim x, y, z As Integer
Try
strtemp01 = Me.txt.Text.Trim()
If strtemp01 = String.Empty Then
Exit Sub
End If
Me.ListBox1.Items.Clear()
dstemp01 = New DataSet
datemp01 = New SqlClient.SqlDataAdapter("select * from [數據庫] where [條件]='" & strtemp01 & "';", connDB)
datemp01.Fill(dstemp01, "datalist")
z = dstemp01.Tables("datalist").Rows.Count
If z = 0 Then
Exit Sub
End If
For x = 0 To z - 1
rw01 = dstemp01.Tables("datalist").Rows(x)
Me.ListBox1.Items.Add(rw01("字段") )
Next
Catch ex As Exception
End Try
combobox 關聯數據庫
Dim dsTemp01 As DataSet
Dim daTemp01 As OleDb.OleDbDataAdapter
Dim rw01 As DataRow
Dim x, y, z As Integer
dsTemp01 = New DataSet
daTemp01 = New OleDb.OleDbDataAdapter("Select [] from [] where []="" ;", connDB)
daTemp01.Fill(dsTemp01, "DataList")
cmbProductType.Items.Clear()
cmbProductType.Items.Add("")
z = dsTemp01.Tables("DataList").Rows.Count
For x = 0 To z - 1
rw01 = dsTemp01.Tables("DataList").Rows(x)
cmbProductType.Items.Add(ReadStr(rw01("")))
Next
cmbProductType.SelectedIndex = -1
connDB為連接數據庫函數