[英]ERROR [42000] [Microsoft][ODBC Visual FoxPro Driver]Syntax error
Hy 海兰
I want to insert into ODBC and I have the error: ERROR [42000] [Microsoft][ODBC Visual FoxPro Driver]Syntax error. 我想插入ODBC,但出现错误:错误[42000] [Microsoft] [ODBC Visual FoxPro驱动程序]语法错误。
My code is: 我的代码是:
string number;
insertStatement = "INSERT INTO " + tabela + " (Data, Fetr, Fldo, Nrdo, Dii) " +
" VALUES ( "+ "@data" +", 'cc','CD', " + number + ","+ dii + ")";
OdbcCommand cmd = new OdbcCommand(insertStatement, this.connection);
cmd.Parameters.Add("@data",OdbcType.DateTime).Value = data;
cmd.ExecuteNonQuery();
The problem is with the data, but I cannot figure out what is the problem. 问题出在数据上,但我无法弄清楚问题出在哪里。
Can someone help me? 有人能帮我吗?
Thanks 谢谢
try with a ? 尝试一个? instead of @data in the query, like this:
而不是查询中的@data,如下所示:
insertStatement = "INSERT INTO " + tabela + " (Data, Fetr, Fldo, Nrdo, Dii) " +
" VALUES ( ? , 'cc','CD', " + number + ","+ dii + ")";
When CommandType is set to Text, the .NET Framework Data Provider for ODBC does not support passing named parameters to an SQL statement or to a stored procedure called by an OdbcCommand.
当CommandType设置为Text时,用于ODBC的.NET Framework数据提供程序不支持将命名参数传递给SQL语句或OdbcCommand调用的存储过程。 In either of these cases, use the question mark (?) placeholder.
在这两种情况下,均使用问号(?)占位符。
UPDATE you could try concatenating your date directly in the insert in this format { d '2011-03-10' }
(see ODBC Datetime Format for reference) and drop the parameter. 更新时,您可以尝试以这种格式
{ d '2011-03-10' }
直接在插入内容中串联日期(请参阅ODBC Datetime格式以获取参考),并删除参数。
insertStatement = "INSERT INTO " + tabela + " (Data, Fetr, Fldo, Nrdo, Dii) " +
" VALUES ( { d '" +
data.ToString("yyyy-MM-dd")
+ "' } , 'cc','CD', " + number + ","+ dii + ")";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.