void CEx2View::OnButijk() 
{
// TODO: Add your control notification handler code hereUpdateData(true);int II=m_II;  int JJ=m_JJ;  int KK=m_KK;
long m_1,m_2,m_3=0;
  
  for(int I=1;I<=II;I++)
  {
  for(int J=1;J<=JJ;J++)
  {
  for(int K=1;K<=KK;K++)
  {   
  CString str;
  //str.Format("select * from frp3 where k='%s' ",K);
  //str.Format("select * from frp3 where i=I and j=J and k=K");
  //str.Format("select * from frp3 where i='%d' and j='%d' and k='%d' ",I,J,K);
  try
  {
  _variant_t RecordsAffected;
  m_pRecordset =m_pConnection->Execute((_bstr_t)str,&RecordsAffected,adCmdText);
  
  _variant_t vCount;  vCount = m_pRecordset->GetCollect("Cijkf");
  m_1=vCount.lVal;
  
  vCount = m_pRecordset->GetCollect("Cijkrp");
  m_2=vCount.lVal;
  
  vCount = m_pRecordset->GetCollect("Cijkcl");
  m_3=vCount.lVal;  m_0=m_1+m_2+m_3;
  }
  catch(_com_error*e)
  {
  AfxMessageBox(e->ErrorMessage());
  }
  
  }
  }
  }  UpdateData(false);}

解决方案 »

  1.   

    str.Format("select * from frp3 where i=2 and j=2 and k=2);可以运行str.Format("select * from frp3 where i='%d' and j='%d' and k='%d' ",I,J,K);不能运行为什么呢?
      

  2.   

    这句忘记加"了,可还是下面的这种情况
    str.Format("select * from frp3 where i=2 and j=2 and k=2");可以运行str.Format("select * from frp3 where i='%d' and j='%d' and k='%d' ",I,J,K);不能运行
      

  3.   

    改成这样试试
    str.Format("select * from frp3 where i=%d and j=%d and k=%d ",I,J,K);
      

  4.   

    这句忘记加"了,可还是下面的这种情况
    str.Format("select * from frp3 where i=2 and j=2 and k=2");可以运行str.Format("select * from frp3 where i='%d' and j='%d' and k='%d' ",I,J,K);不能运行你多加了单引号,没看明白?把单引号去掉啊
      

  5.   

    这句忘记加"了,可还是下面的这种情况
    str.Format("select * from frp3 where i=2 and j=2 and k=2");可以运行str.Format("select * from frp3 where i='%d' and j='%d' and k='%d' ",I,J,K);不能运行你多加了单引号,没看明白?把单引号去掉啊去掉了,可以运行了,谢谢啦