读书人

帮小弟我分析下该如何改?ADO链接数

发布时间: 2012-04-12 15:46:35 作者: rapoo

帮我分析下,该怎么改?ADO链接数据库的
void CChaxunDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
if(conn)
{
if(conn->State!=adStateOpen)
{
AfxMessageBox("Error:can't open~~!");
}
}

pRecordset.CreateInstance((_uuidof(Recordset)));
try
{
CString strSQL;
strSQL.Format(_T("select * from wuxingcanshu where 温度='%s'"),m_wendu);
pRecordset->Open((_bstr_t)strSQL,conn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error&error)
{
CString erroMsg;
erroMsg.Format("error:%s",(LPTSTR)error.Description());
AfxMessageBox(erroMsg);
}
_variant_t vt1;
_variant_t vt2;
_variant_t vt3;
_variant_t vt4;
vt1=pRecordset->GetCollect("密度");
vt2=pRecordset->GetCollect("比热容");
vt3=pRecordset->GetCollect("导热系数");
vt4=pRecordset->GetCollect("动力黏度");
if(vt1.vt==VT_NULL)
{
//AfxMessageBox((LPCSTR)_bstr_t(vt));
AfxMessageBox("Error:NULL~~~!");
}
if(vt2.vt==VT_NULL)
{
//AfxMessageBox((LPCSTR)_bstr_t(vt));
AfxMessageBox("Error:NULL~~~!");
}
if(vt3.vt==VT_NULL)
{
//AfxMessageBox((LPCSTR)_bstr_t(vt));
AfxMessageBox("Error:NULL~~~!");
}
if(vt4.vt==VT_NULL)
{
//AfxMessageBox((LPCSTR)_bstr_t(vt));
AfxMessageBox("Error:NULL~~~!");
}
CString temp1;
temp1=(LPCSTR)_bstr_t(vt1);
CString temp2;
temp2=(LPCSTR)_bstr_t(vt2);
CString temp3;
temp3=(LPCSTR)_bstr_t(vt3);
CString temp4;
temp4=(LPCSTR)_bstr_t(vt4);
m_midu.SetWindowText(temp1);
m_bire.SetWindowText(temp2);
m_daore.SetWindowText(temp3);
m_dongli.SetWindowText(temp4);
UpdateData(FALSE);

}

错误主要在SQL查询里,执行的时候,出现错误窗口:“error:标准表达式中数据类型不匹配。”

[解决办法]
既然是浮点类型,改成这样:
strSQL.Format(_T("select * from wuxingcanshu where 温度=%5.1f"),m_wendu);

[解决办法]
怎么还是这个问题啊
如果m_wendu是CString,那么
strSQL.Format(_T("select * from wuxingcanshu where 温度=%s"),m_wendu);

如果m_wendu是float或double,那么
strSQL.Format(_T("select * from wuxingcanshu where 温度=%f"),m_wendu);

如果m_wendu是int,那么
strSQL.Format(_T("select * from wuxingcanshu where 温度=%d"),m_wendu);

如果m_wendu是CEdit,那么
CString wendu;
m_wendu.GetWindowText(wendu);
strSQL.Format(_T("select * from wuxingcanshu where 温度=%s"),wendu);

读书人网 >VC/MFC

热点推荐