SQLLite更新查询参数不接受系统字符串值



我有一个参数化的SQL Lite查询的一些问题。我似乎无法让SQL Lite参数接受字符串值

Using cmd As SQLiteCommand = pConn.CreateCommand()
    If tblLang = "en" Then
        cmd.CommandText = "UPDATE [AT_Strings] SET [Data] = @tblData + 1 WHERE [RecordID] = @ID AND [language] = @tblLang1"
        Dim tblData As New SQLiteParameter("@tblData")
        Dim ID As New SQLiteParameter("@ID")
        Dim tblLang1 As New SQLiteParameter("@tblLang1")
        cmd.Parameters.Add(dataText)
        cmd.Parameters.Add(ID)
        cmd.Parameters.Add(tblLang)
    Else
         cmd.CommandText = "UPDATE [AT_Strings] SET [Data] = @dataText + 1 WHERE [RecordID] = @ID AND [language] = @tblLang1"
         Dim tblData As New SQLiteParameter("@dataText")
         Dim ID As New SQLiteParameter("@ID")
         Dim tblLang1 As New SQLiteParameter("@tblLang1")
         cmd.Parameters.Add(dataText)
         cmd.Parameters.Add(ID)
         cmd.Parameters.Add(tblLang)
    End If
    cmd.ExecuteNonQuery()
 End Using

错误如下....

Unable to cast object of type 'System.String' to type 'System.Data.SQLite.SQLiteParameter'. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Data.SQLite.SQLiteParameter'.
Source Error: 
Line 283:  Dim ID As New SQLiteParameter("@ID")
Line 284:  Dim tblLang1 As New SQLiteParameter("@tblLang1")
ERROR on Line 285...
Line 285:  cmd.Parameters.Add(dataText)

我是这样解决这个问题的

Dim SqlString As String 
SqlString = "UPDATE [AT_Strings] SET [Data] = @Data WHERE [ID] = @ID AND [Language] = @Language"  
Using cmd As New SQLiteCommand(SqlString, pConn)    
    cmd.CommandType = CommandType.Text     
    cmd.Parameters.AddWithValue("Data", dataText)    
    cmd.Parameters.AddWithValue("ID", f4)    
    cmd.Parameters.AddWithValue("Language", tblLang)     
    pConn.Open()    
    cmd.ExecuteNonQuery()    
    pConn.Close() 
End Using 

希望这对其他人有帮助!!

相关内容

  • 没有找到相关文章

最新更新