我有一個包含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
這裏的「操作」 &(我)是指數據庫,已命名爲喜歡的operation1,操作2等的字段名...
這段代碼似乎不適合我。請幫助..
Me.Controls指的是直接包含在窗體中的控件。如果文本框位於組框中,您需要使用該組合框的控件集合 – Steve 2013-04-20 10:41:12
@Steve:那麼我該怎麼做?我仍然在學習vb.net ... – SaurabhSuman 2013-04-20 10:42:10
順便說一下,說'代碼似乎沒有工作'真的很煩人。如果你不告訴我們什麼不工作,我們如何能夠幫助你? – Steve 2013-04-20 10:42:23