这次变量主要针对 Mfc 的 Cstring 类型的变量(前面VC
链接Access 数据库 插入变量到表)
思路;
1 把cstring 类型 转为 string
2 string 转 char 数组
3 sprintf 写入数组
string 转 char 数组函数
[cpp] view
plaincopyprint?
- 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;
- }
代码参考:
[cpp] view
plaincopyprint?
- 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);
这个算一个实用的方法吧!其他方法我还没用到,也欢迎有好方法的可以交流!
时间: 2024-10-26 01:24:18