int i,j;
i=GetDlgItemInt(IDC_xuehaocha);
         j=GetDlgItemInt(IDC_yearcha);
         CString str1,str2;
str1.Format("%d",i);
str2.Format("%d",j);
         try
{ m_pRecordset.CreateInstance("ADODB.Recordset");

m_pRecordset->Open("SELECT * FROM jiaofei WHERE Fyear='"+str+"'",_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
}
catch(_com_error &e)
{
AfxMessageBox(e.Description());
}i和j是我从编辑框里读取的数据。想以他们为条件找到数据库查找记录并更新。
运行的时候老报错
1.error C2664: 'Open' : cannot convert parameter 1 from 'class CString' to 'const class _variant_t &'
2.cannot convert from 'class CString' to 'const class _variant_t'请问哪位能帮我解决解决这个问题,感谢了

解决方案 »

  1.   


    m_pRecordset->Open(_variant_t("SELECT * FROM jiaofei WHERE Fyear='"+str+"'"),_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
    }
      

  2.   

    字符串转换出错,
    LPTSTR   lpType;   
      CString   m_strFileName;   
      CString   strTmp;   
      strTmp   =   m_strFileName.Right(3);       //从右取3个   
      lpType   =   LPCTSTR(strTmp);     //强制转换   
      

  3.   

    CString strSQL;
    strSQL = SELECT * FROM jiaofei WHERE Fyear='"+str+"';
    m_pRecordset->Open(_varian_t((LPCTSTR)strSQL),_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
    }
      

  4.   

    CString strSQL;
    strSQL.Format(_T("SELECT * FROM jiaofei WHERE Fyear='%s'"), str);
    m_pRecordset->Open(_varian_t((LPCTSTR)strSQL),_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
    }
      

  5.   

    这样会报错 error C2065: '_varian_t' : undeclared identifier