我有一个包含 6 个组框的表单,每个组框包含 180 个文本框,以及两个组合框。从第一个组合框中选择一个值后,第二个组合框将填充表中所需的数据。我的要求是,从第二个组合框中选择一个值后,来自同一个表的过滤数据应该填充剩余的文本框。我正在使用的代码如下:
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=c:\\users\\brisingr\\documents\\123\database.mdb"
Dim objConnection As New OleDbConnection(strConnection)
Dim strsql As String
'strsql = "Select * from '" & ComboBox1.Text & "' where Style = '" & ComboBox2.Text & " '"
Dim a As String
Dim b As String
Dim c As String
Dim d As String
a = "Select * from ["
b = ComboBox1.Text
c = "] where Style = ["
d = ComboBox2.Text
strsql = a & b & c & d & "]"
Dim objCommand As New OleDbCommand(strsql, objConnection)
Dim objDataAdapter As New OleDbDataAdapter(objCommand)
Dim objDataTable As New DataTable("Buyers")
objDataAdapter.Fill(objDataTable)
objConnection.Close()
objConnection.Dispose()
objConnection = Nothing
objCommand.Dispose()
objCommand = Nothing
objDataAdapter.Dispose()
objDataAdapter = Nothing
For i As Integer = 1 To 60
Me.Controls("L1Ob" & i).Text = objDataTable.Rows(0)("Operation" & i)
Next
End Sub
这里的“Operation” & (i) 指的是数据库的字段名,已经命名为 operation1、operation2 等等……
这段代码似乎对我不起作用。请帮忙..