5

以下是变量的声明:

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

...做一些“cin”语句来获取数据...

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 工作正常并存储在表中......但我不知道如何让字符串存储......

4

2 回答 2

8

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 [Deferred Input] 指向参数数据缓冲区的指针。有关详细信息,请参阅“注释”中的“ParameterValuePtr 参数”。

BufferLength [Input/Output] ParameterValuePtr 缓冲区的长度(以字节为单位)。有关详细信息,请参阅“注释”中的“BufferLength 参数”。

于 2008-10-06T22:45:43.950 回答
0

它看起来像 api,想要一个unsigned char * 尝试使用c_str()方法调用传入 ac 字符串。

于 2008-10-06T22:29:35.513 回答