C ++ SQLBindParameter
-
05-07-2019 - |
質問
変数の宣言は次のとおりです。
string strFirstName;
string strLastName;
string strAddress;
string strCity;
string strState;
double dblSalary;
string strGender;
int intAge;
...いくつかの" cin&quot ;;データを取得するステートメント...
retcode = SQLPrepare(StatementHandle, (SQLCHAR *)"INSERT INTO EMPLOYEE ([FirstName], [LastName], [Address], [City], [State], [Salary], [Gender],[Age]) VALUES (?,?,?,?,?,?,?,?)", SQL_NTS);
retcode = SQLBindParameter(StatementHandle, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 50, 0 &strFirstName,0, NULL);
retcode = SQLBindParameter(StatementHandle, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 50, 0, &strLastName,0, NULL);
retcode = SQLBindParameter(StatementHandle, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 30, 0, &strAddress,0, NULL);
retcode = SQLBindParameter(StatementHandle, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 30, 0, &strCity,0, NULL);
retcode = SQLBindParameter(StatementHandle, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 3, 0, &strState,0, NULL);
retcode = SQLBindParameter(StatementHandle, 6, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, 0, 0, &dblSalary,0, NULL);
retcode = SQLBindParameter(StatementHandle, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 2, 0, &strGender,0, NULL);
retcode = SQLBindParameter(StatementHandle, 8, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &intAge,0, NULL);
retcode = SQLExecute(StatementHandle);
intとdoubleは正常に機能し、テーブルに格納されますが、格納する文字列を取得する方法がわかりません...
解決
SQLBindParameterのMSDNドキュメントは、バッファを渡すことを意図していると述べています ParameterValuePtr
のデータと、 BufferLength
:
retcode = SQLBindParameter(StatementHandle, 1, SQL_PARAM_INPUT, SQL_C_CHAR,
SQL_LONGVARCHAR, 50, 0, strFirstName.c_str(), strFirstName.length(), NULL);
ParameterValuePtr [遅延入力] A のバッファへのポインタ パラメータのデータ。多くのための 情報については、" ParameterValuePtr 引数" " Comments。"
BufferLength [入力/出力]の長さ ParameterValuePtrバッファー(バイト単位)。 詳細については、 " BufferLength引数" " Comments。"
他のヒント
APIのように見えますが、 unsigned char * が必要です c_str()メソッド呼び出しを使用してc文字列を渡してみてください。
所属していません StackOverflow