本文介绍了参数化查询抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码。我想使用参数将值传递给我的查询。
公共共享函数FillStates(ByVal strState As String)As DataSet Dim ds As New DataSet Dim da As New iDB2DataAdapter Dim cn as iDB2Connection = CreateConnection()尝试如果strState.Length< = 0那么 Dim cm As New iDB2Command(SELECT * FROM DEVSUSH.CLSTATES,cn) da.SelectCommand = cm da.Fill(ds) Else Dim cm As New iDB2Command(SELECT * FROM DEVSUSH.CLSTATES Where STCODE ='@ strState,cn) cm.Parameters.Add(@ strState,iDB2DbType.iDB2VarChar).Value = strState da.SelectCommand = cm da .Fill(ds)结束如果 Catch ex As Exception LogError.LogErrorIntoTextFile(例如,FillStates())最后 cn.Cl ose()结束尝试返回ds 结束功能我收到错误说
SQL语句文本无效。格式异常。 有人可以帮我吗?
解决方案取消报价! 昏暗 cm 作为 新 iDB2Command( SELECT * FROM DEVSUSH.CLSTATES其中STCODE ='@ strState,cn)
成为
Dim cm 作为 新 iDB2Command( SELECT * FROM DEVSUSH.CLSTATES其中STCODE = @ strState,cn)
Here is my code. I want to use parameters to pass the values to my queries.
Public Shared Function FillStates(ByVal strState As String) As DataSet Dim ds As New DataSet Dim da As New iDB2DataAdapter Dim cn As iDB2Connection = CreateConnection() Try If strState.Length <= 0 Then Dim cm As New iDB2Command("SELECT * FROM DEVSUSH.CLSTATES", cn) da.SelectCommand = cm da.Fill(ds) Else Dim cm As New iDB2Command("SELECT * FROM DEVSUSH.CLSTATES Where STCODE='@strState", cn) cm.Parameters.Add("@strState", iDB2DbType.iDB2VarChar).Value = strState da.SelectCommand = cm da.Fill(ds) End If Catch ex As Exception LogError.LogErrorIntoTextFile(ex, "FillStates()") Finally cn.Close() End Try Return ds End FunctionI get an error saying
The SQL statement text is not valid.Format exception. Could someone help me with this?
解决方案 Take off the quote! Dim cm As New iDB2Command("SELECT * FROM DEVSUSH.CLSTATES Where STCODE='@strState", cn)Becomes
Dim cm As New iDB2Command("SELECT * FROM DEVSUSH.CLSTATES Where STCODE=@strState", cn)更多推荐
参数化查询抛出错误
发布评论