如何在ODBC C ++中将数据插入表中

时间:2019-05-28 09:41:11

标签: c++ database odbc

一种方法是:

char SQLQuery[] = "INSERT INTO people(name, age) VALUES ( 'patrick', '23')";

        if (SQL_SUCCESS != SQLExecDirect(SQLStatementHandle, (SQLCHAR*)SQLQuery, SQL_NTS)) {
            // Executes a preparable statement
            showSQLError(SQL_HANDLE_STMT, SQLStatementHandle);
            break;
        }

但是如果我想向sqlquery添加整数和字符串怎么办

string myString = "patrick";
int myInt = 23;

char SQLQuery[] = "INSERT INTO people(name, age) VALUES ( 'myString', 'myAge')";

        if (SQL_SUCCESS != SQLExecDirect(SQLStatementHandle, (SQLCHAR*)SQLQuery, SQL_NTS)) {
            // Executes a preparable statement
            showSQLError(SQL_HANDLE_STMT, SQLStatementHandle);
            break;
        }

0 个答案:

没有答案