m_pRs->Open("select * from 表 where 字段=变量",.....);
请问高手,如果我的变量int stuno;该如何正确放到“变量的位置”?
在线急等,马上结帖。

解决方案 »

  1.   

    CString sql;
    sql.Format("("select * from 表 where 字段=%d", stuno);
    m_pRs->Open(sql,....);
      

  2.   

    好象不对呀,会报错:
    “Runtime Error
      abnormal program termination”
      

  3.   

    CString str;
    str.Format("%d", stuno);
    CString sql="select * from 表 where 字段=";
    sql += str;
      

  4.   

    CString sql;
    sql.Format("("select * from 表 where 字段=%d", stuno);
    m_pRs->Open( (_variant_t)sql,....);
      

  5.   

    to taianmoney and cdwy411
    我照你们的做了,还是不行,报错:
    Runtime Error
    abnormal program termination还问一下,sql.Format("("select * from 表 where 字段=%d", stuno);
    此句的"("在此起什么作用?
      

  6.   

    sql.Format("("select * from 表 where 字段=%d", stuno);
    改为
    sql.Format("select * from 表 where 字段=%d", stuno);
      

  7.   

    to AkiraChing
    照你的做了,报错:
    cannot convert from 'class CString' to 'const class _variant_t急呀,到底哪儿出问题了?
      

  8.   

    试试m_pRs->Execute((_bstr_t)sql,...)
      

  9.   

    我回去试了多次,终于明白了,
    m_pRs->Open("select * from 表 where id=\'"+stuno+"\'",);
    可以了。