我有以下代码:
Dim executedCmd As OleDb.OleDbCommand = m_dbMgr.GetCommand()
executedCmd.CommandText = "select * from [Parameters] where "
Dim SQLcondition As String = String.Empty
For i As Integer = 0 To ParameterName.Count - 1
executedCmd.CommandText += "ParameterName = @parametername" + i.ToString() + " and ParameterValue @ParamaterCondition" + i.ToString() + " @ParameterValue" + i.ToString()
executedCmd.Parameters.AddWithValue("@parametername" + i.ToString(), ParameterName(i))
executedCmd.Parameters.AddWithValue("@ParameterValue" + i.ToString(), ParameterValue(i))
executedCmd.Parameters.AddWithValue("@ParamaterCondition" + i.ToString(), Condition(i))
Next
ParameterName
, ParameterValue
, ParameterCondition
all are the same length ArrayList
,但代码无法正常工作。我已经验证了所有变量都有值。
当我运行代码时,它报告语法错误:“查询表达式中缺少操作”
问题在于它ParameterCondition
的值如 ( '>'
, '<'
, '='
,.... 一些逻辑 SQL 运算符)。
编辑:如何在参数中包含条件?