user599977
user599977

Reputation: 331

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

Upvotes: 0

Views: 3460

Answers (1)

Paolo Falabella
Paolo Falabella

Reputation: 25844

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

Upvotes: 1

Related Questions