这次变量主要针对 Mfc 的 Cstring 类型的变量(前面VC 链接Access 数据库 插入变量到表)
思路;
1 把cstring 类型 转为 string
2 string 转 char 数组
3 sprintf 写入数组
string 转 char 数组函数
- char* zhuanhuan(std::string src)
- {
- char *dst = new char[255];
- int i;
- int j=src.length();
- for(i=0;i <src.length();i++)
- dst[i]=src[i];
- dst[i] = '\0';
- return dst;
- }
- openAccess();
- CString cmbParam = L"SelfImprovement";
- std::string a1=(CT2A)(cmbParam.GetBuffer());
- char buff[256] = {0};
- sprintf(buff, "select * from tb_YCType where YCName = '%s' order by YCType desc",zhuanhuan(a1));
- m_pRecordset = m_pConnection->Execute(buff, &RecordsAffected, adCmdText);