简体   繁体   English

错误[42000] [Microsoft] [ODBC Visual FoxPro驱动程序]语法错误

[英]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 + ")"; 

Msdn says: Msdn说:

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.

相关问题 Microsoft Visual Foxpro语法 - Microsoft Visual Foxpro Syntax FoxPro OLEDB驱动程序导入数据时出错 - Error importing data with FoxPro OLEDB driver 我的SQL连接错误Microsoft] [ODBC驱动程序管理器]找不到数据源名称,并且未指定默认驱动程序 - My Sql Connection error Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified Postgresql odbc驱动程序错误c#[IM002] [Microsoft] [ODBC驱动程序管理器]找不到数据源名称 - Postgresql odbc driver error c# [IM002] [Microsoft][ODBC Driver Manager] Data source name not found Sqlcmd:错误:Microsoft ODBC Driver 17 for SQL Server:用户“SA”登录失败 - Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'SA' 附加信息:错误[IM002] [Microsoft] [ODBC驱动程序管理器]找不到数据源名称,并且未指定默认驱动程序 - Additional information: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified Visual Studio上的Visual Foxpro查询执行错误(表中的触发器失败) - Visual Foxpro query execution error on Visual studio (Trigger failed in table) 从C#通过ODBC访问Sql Server:错误[IM002] [Microsoft] [ODBC驱动程序管理器]找不到数据源名称,并且未指定默认驱动程序 - Access to Sql Server via ODBC from C# : ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified Visual Studio 2010和FoxPro 9.0运行时错误:“功能不可用。” - Visual Studio 2010 and FoxPro 9.0 runtime Error: “Feature is not available.” 错误:Informix ODBC驱动程序网络驱动程序无法打开网络设备 - Error: Informix ODBC Driver Network driver cannot open the network device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM