Pregunta

Aquí están las declaraciones de las variables:

string strFirstName;
string strLastName;
string strAddress;
string strCity;
string strState;
double dblSalary;
string strGender;
int intAge;

... Hacer algo de " cin " declaraciones para obtener datos ...

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

El int y el doble funcionan bien y se almacenan en la tabla ... pero no puedo averiguar cómo hacer que las cadenas se almacenen ...

¿Fue útil?

Solución

La documentación de MSDN para SQLBindParameter dice que debes pasar un búfer que contiene los datos para ParameterValuePtr y la longitud del búfer en 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 diferida] A   puntero a un búfer para el   Datos del parámetro. Para más   información, vea " ParameterValuePtr   Argumento " en " Comentarios. "

     

BufferLength [Input / Output] Longitud de   El búfer ParameterValuePtr en bytes.   Para más información, ver   " Argumento de longitud de búfer " en " Comentarios. "

Otros consejos

Se parece a la API, quiere un personaje sin firma * intente pasar una cadena c utilizando el método c_str () .

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top