开发者

ERROR [42000] [Microsoft][ODBC Visual FoxPro Driver]Syntax error

开发者 https://www.devze.com 2023-02-16 03:04 出处:网络
Hy I want to insert into ODBC and I have the error: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.

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.conn开发者_如何学JAVAection);             

        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:

insertStatement = "INSERT INTO " + tabela + " (Data, Fetr, Fldo, Nrdo, Dii) " +
        " VALUES ( ? , 'cc','CD', " +  number + ","+ dii + ")"; 

Msdn says:

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. 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.

insertStatement = "INSERT INTO " + tabela + " (Data, Fetr, Fldo, Nrdo, Dii) " +
            " VALUES ( { d '" +
            data.ToString("yyyy-MM-dd") 
             + "' } , 'cc','CD', " +  number + ","+ dii + ")";
0

精彩评论

暂无评论...
验证码 换一张
取 消