您好我需要使用另一个组合中的选定值填充组合框。我使用的编码不会产生所需的输出。我有一个带有名为“BaseStation”的列的excel表。 “扇区”。 Combobox2必须显示相对于所选BaseStation的相关扇区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
答案 0 :(得分:0)
尝试在BaseStation参数周围添加单引号:
cmd.CommandText = "SELECT * FROM [Sheet1$] WHERE BaseStation='" & ComboBox1.Text & "'"