以下是变量的声明:

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工作正常并存储在表中......但我无法弄清楚如何将字符串存储...

有帮助吗?

解决方案

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   参数"在“评论”中。

     

BufferLength [输入/输出]长度   ParameterValuePtr缓冲区,以字节为单位。   有关更多信息,请参阅   “BufferLength Argument”在“评论”中。

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top