所以我有一个访问数据库,其中包含三列:制造,夹具和模式
我正在使用以下代码在表单中创建级联组合框。
Imports System.Data.OleDb
Public Class Add_Fixtures
Dim con As New OleDbConnection
Dim constring As String
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
Dim cmd1 As New OleDbCommand
Dim dr1 As OleDbDataReader
Dim cmd2 As New OleDbCommand
Dim dr2 As OleDbDataReader
Private Sub Add_Fixtures_Load(sender As Object, e As EventArgs) Handles Me.Load
constring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/FixtureLibrary.accdb"
With con
.ConnectionString = constring
.Open()
End With
With cmd
.Connection = con
.CommandType = CommandType.Text
.CommandText = "SELECT DISTINCT Fixtures.Manufacture from Fixtures;"
End With
dr = cmd.ExecuteReader()
While dr.Read
cbManufacture.Items.Add(dr("Manufacture"))
End While
With cmd1
.Connection = con
.CommandType = CommandType.Text
.CommandText = "SELECT from Fixtures where [Manufacture]='" & Me.cbManufacture.Text & "';"
End With
dr1 = cmd1.ExecuteReader()
While dr1.Read
cbFixture.Items.Add(dr1("Fixture"))
End While
With cmd2
.Connection = con
.CommandType = CommandType.Text
.CommandText = "SELECT DISTINCT Fixtures.Mode from Fixtures where [Fixture] ='" & Me.cbFixture.Text & "';"
End With
dr2 = cmd2.ExecuteReader()
While dr2.Read
cbMode.Items.Add(dr2("Mode"))
End While
End Sub
End Class
但是在这一行:dr1 = cmd1.ExecuteReader()
我收到此错误
System.Data.OleDb.OleDbException:“ SELECT语句包含一个保留字或一个拼写错误或丢失的参数名称,或者标点符号不正确。”
任何人都知道是什么原因或原因吗?
欢呼
答案 0 :(得分:0)
您不选择任何字段,并且属性 Text 仅对具有焦点的控件有效,因此:
.CommandText = "SELECT * from Fixtures where [Manufacture]='" & Me.cbManufacture.Value & "';"