0
嗨,我需要在另一個組合框中使用選定的值填充組合框。我使用的編碼不會產生所需的輸出。我有一個名爲「基站」&「SectorID」的列的Excel表。 Combobox2必須顯示相對於所選基站的相關扇區ID使用另一個組合框中的選擇來填充組合框
以下給出的是我得到的錯誤: 「查詢表達式'BaseStation ='中的語法錯誤(缺少運算符)。」
請幫忙。下面的編碼給出:
Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged
Using cn As New OleDb.OleDbConnection With _
{ _
.ConnectionString = _
<S>
provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:\WalkAir Customers.xls;
Extended Properties="Excel 8.0; HDR=Yes;"
</S>.Value _
}
Dim cmd As New OleDb.OleDbCommand
Dim dr As System.Data.IDataReader
cn.Open()
cmd = New OleDb.OleDbCommand()
cmd.Connection = cn
cmd.CommandText = "SELECT * FROM [Sheet1$] WHERE BaseStation=" & ComboBox1.Text
Dim dtData As New DataTable
dr = cmd.ExecuteReader
dtData.Load(dr)
dtData.Columns("SectorID").ColumnMapping = MappingType.Hidden
bsCustomers.DataSource = dtData
End Using
ComboBox2.DisplayMember = "SectorID"
ComboBox2.DataSource = bsCustomers
End Sub
,做你所得到的輸出,並且將你的期望? – APrough 2012-01-30 18:06:39