以下是变量的声明:
string strFirstName;
string strLastName;
string strAddress;
string strCity;
string strState;
double dblSalary;
string strGender;
int intAge;...Do一些"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);整型和双精度型可以很好地工作,并存储在table...but中,我不知道如何存储字符串……
发布于 2008-10-06 22:45:44
MSDN documentation for SQLBindParameter表示,您应该传递一个缓冲区,其中包含ParameterValuePtr的数据和BufferLength的缓冲区长度(以字节为单位
retcode = SQLBindParameter(StatementHandle, 1, SQL_PARAM_INPUT, SQL_C_CHAR,
SQL_LONGVARCHAR, 50, 0, strFirstName.c_str(), strFirstName.length(), NULL);ParameterValuePtr延迟输入指向参数数据缓冲区的指针。有关详细信息,请参阅“注释”中的"ParameterValuePtr参数“。
ParameterValuePtr缓冲区的BufferLength输入/输出长度,以字节为单位。有关详细信息,请参阅“注释”中的"BufferLength参数“。
发布于 2008-10-06 22:29:36
它看起来像api,想要一个unsigned char *尝试使用c_str()方法调用传入一个c字符串。
https://stackoverflow.com/questions/176459
复制相似问题