ODBC Insert Question.

I’m having a little trouble mixing data types in my ODBC insert. I know the connection and the table names are set up correctly because I can add hard values in the code and it inserts just fine. When I try to add my variables in the Insert string I am having trouble with the syntax. How do I mix string and double variables in the same insert statement?

    sql = "Insert INTO tblDebug(StringValue1, StringValue2, DoubleValue1, StringValue3, DoubleValue2) " +_
    "Values('" + varStringValue1 + "', '" + varStringValue2 + "', varDoubleValue1, '" + varStringValue3 + "', varDoubleValue2)"

What do I have to change in the above code to get varDoubleValue1 and varDoubleValue2 variables to insert? Thanks!

When you’re doing a SQL Pass through, basically everything becomes a string that gets executed. Doubles must become strings.

sql = "Insert INTO tblDebug (StringValue1, StringValue2, DoubleValue1, StringValue3, DoubleValue2) " +_ "Values " + _ "('" + varStringValue1 + "', '" + varStringValue2 + "', " + CSTR(varDoubleValue1) + ", " + _ "'" + varStringValue3 + "', " + CSTR(varDoubleValue2) + ");"

There will be people advocating using using the SQLPrepareStatement in 3 … 2 … 1 … but I do enjoy pasting in the value of the variable ‘sql’ into PGAdmin for PostgreSQL and testing my SQL statement.

Thank you sir I will give this a try.

@Kevin Cully Worked perfect!