我尝试在C#中运行查询,但它不起作用,尽管查询是正确的

时间:2016-04-09 19:23:22

标签: c# sqlite

sqlQuery = "INSERT INTO community_market" +
           "VALUES (" + a.transaction_id + ",'" + a.community_name + "'," + 
                    a.community_id + ",'" + a.item_name + "'," +
                    a.item_quantity + "," + a.price + ");";

这是我正在尝试运行的查询,我得到的错误是:

  

SqliteSyntaxException:near" 1":语法错误   Mono.Data.SqliteClient.SqliteCommand.GetNextStatement(IntPtr pzStart,System.IntPtr& pzTail,System.IntPtr& pStmt)   Mono.Data.SqliteClient.SqliteCommand.ExecuteReader(CommandBehavior behavior,Boolean want_results,System.Int32& rows_affected)   Mono.Data.SqliteClient.SqliteCommand.ExecuteReader(CommandBehavior行为)   Mono.Data.SqliteClient.SqliteCommand.ExecuteDbDataReader(CommandBehavior行为)   System.Data.Common.DbCommand.ExecuteReader()   System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()

可以使用一些帮助

1 个答案:

答案 0 :(得分:5)

我想你忘记了community_marketVALUES之间的空格:

sqlQuery = "INSERT INTO community_market " +
"VALUES("+a.transaction_id+",'"+ a.community_name+"',"+ 
a.community_id+",'"+ a.item_name+"',"+ a.item_quantity+","+a.price+");";

此外,SQL Injection可能会引起一些兴趣。