本文介绍了C ++ SQLBindParameter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是变量的声明:
string strFirstName;
string strLastName;
string strAddress;
string strCity;
string strState;
double dblSalary;
string strGender;
int intAge;
...执行一些cin语句获取数据...
<$ c $ p>
retcode = SQLPrepare(StatementHandle,(SQLCHAR *)INSERT INTO EMPLOYEE([FirstName],[LastName],[Address],[City]状态],[薪金],[性别],[年龄])VALUES(?,?,?,?
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工作正常,并存储在表...但我不能如何获取字符串存储...
解决方案
说,你的意思是传递一个包含 ParameterValuePtr
的数据的缓冲区,缓冲区以字节为单位 BufferLength
:
retcode = SQLBindParameter(StatementHandle, 1,SQL_PARAM_INPUT,SQL_C_CHAR,
SQL_LONGVARCHAR,50,0,strFirstName.c_str(),strFirstName.length(),NULL);
Here are the declarations of the variables:
string strFirstName;
string strLastName;
string strAddress;
string strCity;
string strState;
double dblSalary;
string strGender;
int intAge;
...Do some "cin" statements to get data...
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);
The int and double work fine and get stored in the table...but I can't figure out how to get the strings to store...
解决方案
MSDN documentation for SQLBindParameter says you are meant to pass a buffer containing the data for ParameterValuePtr
and the length of the buffer in bytes for BufferLength
:
retcode = SQLBindParameter(StatementHandle, 1, SQL_PARAM_INPUT, SQL_C_CHAR,
SQL_LONGVARCHAR, 50, 0, strFirstName.c_str(), strFirstName.length(), NULL);
这篇关于C ++ SQLBindParameter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!