我有以下代码,当我运行它并且代码行结束时,我得到一个错误状态
System.Data.OleDb.OleDbException:'语法错误(缺少运算符)in 查询表达式
但我不确定这意味着什么,我正在使用vb(在visual studio中)和访问数据库。错误出现在我声明dr
变量(我用于数据读取器)的行上。
对此的任何帮助将非常感谢,非常感谢,
Private Function CarFinder(b As String, m As String, s As String, d As Integer, e As String)
myConnection.ConnectionString = My.Forms.Main.connString
myConnection.Open()
Dim match As String
match = "SELECT * FROM CarFigures WHERE CBrand = '" & cbBrand.Text & "' CModel = '" &
cbModel.Text & "' and CSpec = '" & cbSpec.Text & "'"
Using cmd As New OleDb.OleDbCommand(match, myConnection)
cmd.Parameters.AddWithValue("@b", b)
cmd.Parameters.AddWithValue("@m", m)
cmd.Parameters.AddWithValue("@s", s)
cmd.Parameters.AddWithValue("@d", d)
cmd.Parameters.AddWithValue("@e", e)
Dim dr = cmd.ExecuteReader()
If dr.Read Then
CO2e = dr("CCO2")
Ins = dr("InsuranceBand")
mpg = dr("CMPG")
time = dr("C060Time")
ncap = dr("CarNCAP")
bik = dr("Bik Rating")
End If
答案 0 :(得分:0)
看起来你的SQL查询字符串是错误的。你错过了AND
" cbBrand.Text"和" CModel ="。它应该像以下......
match = "SELECT * FROM CarFigures WHERE CBrand = '" & cbBrand.Text & "' and CModel = '" & cbModel.Text & "' and CSpec = '" & cbSpec.Text & "'"