++ SQLBindParameter C
-
05-07-2019 - |
Pergunta
Estas foram as declarações das variáveis:
string strFirstName;
string strLastName;
string strAddress;
string strCity;
string strState;
double dblSalary;
string strGender;
int intAge;
... Faça alguma "cin" declarações para obter dados ...
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);
O int e multa trabalho de casal e ficam armazenados na tabela ... mas eu não consigo descobrir como obter as cordas para loja ...
Solução
documentação do MSDN para SQLBindParameter diz você está destinado a passar um buffer contendo os dados para ParameterValuePtr
e o comprimento do tampão em bytes para BufferLength
:
retcode = SQLBindParameter(StatementHandle, 1, SQL_PARAM_INPUT, SQL_C_CHAR,
SQL_LONGVARCHAR, 50, 0, strFirstName.c_str(), strFirstName.length(), NULL);
ParameterValuePtr [Entrada diferidos] A ponteiro para uma memória intermédia para o dados do parâmetro. Para mais informações, consulte "ParameterValuePtr Argumento" em "Comentários".
BufferLength [Entrada / Saída] Comprimento de tamponar a ParameterValuePtr em bytes. Para mais informações, veja "BufferLength argumento" em "Comentários".
Outras dicas
Parece que a api, quer uma unsigned char * Tente passar de uma série c, usando o c_str () chamada de método.