//其中strSQL是你的查询语句,m_pConnection是你的数据库连接对象
//
m_pRecordSet.CreateInstance(__uuidof(Recordset));
try
{
m_pRecordSet->Open((_bstr_t)strSQL, m_pConnection.GetInterfacePtr(),
adOpenDynamic, adLockOptimistic, adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}if (!m_pRecordSet->IsEOF)
{
CString str = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("RNAME");
MessageBox(str);
}m_pRecordSet->Close();
//
m_pRecordSet.CreateInstance(__uuidof(Recordset));
try
{
m_pRecordSet->Open((_bstr_t)strSQL, m_pConnection.GetInterfacePtr(),
adOpenDynamic, adLockOptimistic, adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}if (!m_pRecordSet->IsEOF)
{
CString str = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("RNAME");
MessageBox(str);
}m_pRecordSet->Close();
解决方案 »
- 读取TXT文件,设置数组大小
- windows 消息机制 关于getmessage
- 请高手提供思路或相关例子,如何实现这样的按钮功能?
- 我想在vs2003环境下,学习用MFC开发ActiveX控件,大家谁有什么好的教程,请发给我.
- 在对话框工程中显示图片的问题
- VC中嵌入Excel,要在Excel中时时得到选中的起始行列,如何捕捉这个消息???????????????????????
- MFC如何读取wav格式的音频文件?求助~求抱大腿~~~
- 如何有效的减少程序的内存占用量
- 能从CBitmap类继承一个新类CMyBitmap吗?
- 奇怪为什么我定义的全局变量在其他cpp中不能用?
- 有汉字字符串的截取
- 急等!
CString str = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("RNAME");
若字段中无值的话,就会出错建议用下面的方法来获值:
_variant_t GetValue;
GetValue=m_pRecordset->GetCollect("RNAME");
if(GetValue.vt!=VT_NULL)
{
str=(LPCTSTR)_bstr_t(GetValue);
}
else
{
str="";
}
//其中strSQL是你的查询语句,m_pConnection是你的数据库连接对象 m_pRecordSet.CreateInstance(__uuidof(Recordset));
try
{
m_pRecordSet->Open((_bstr_t)strSQL, m_pConnection.GetInterfacePtr(),
adOpenDynamic, adLockOptimistic, adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
} if (!m_pRecordSet->BOF)
{
m_pRecordSet->MoveFirst();
CString str = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("RNAME");
MessageBox(str);
}