参考了下面这篇文章
http://topic.youkuaiyun.com/t/20041015/09/3458038.html
CString变量
str = "2008北京奥运";
buf = (LPSTR)(LPCTSTR)str;
BSTR类型的_variant_t变量
v1 = (_bstr_t)"程序员";
buf = _com_util::ConvertBSTRToString((_bstr_t)v1);
_RecordsetPtr m_pRecordSet;
m_pRecordSet.CreateInstance(__uuidof(Recordset));
CString strSql = "select 时间, 表码 from 电量 where 编号 = '"+tableNo+"' and 时间> #"
+strStart+"# and 时间<#"+strEnd+"#";
_variant_t v;
v.ChangeType(VT_BSTR,NULL);
v.bstrVal = (_bstr_t)strSql;
// 如果直接把CString 放到Open的第一个参数,编译时没有问题,运行时会弹出异常。
try
{
m_pRecordSet->Open(v,
m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch (_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
本文介绍了在C++中CString与BSTR类型之间的转换方法,并展示了如何使用转换后的字符串作为ADO Recordset对象的查询参数,以实现数据库查询功能。
3551

被折叠的 条评论
为什么被折叠?



