我已经在SQL2000里面建好了表,然后VC里用MFC建立了操作界面,成员变量也设定好了。
ODBC连接数据库。
但是我不知道写什么语句可以对表进行查询之类的操作,请教了。
谢谢

解决方案 »

  1.   

    CString strSQL;
    strSQL = your sql string;Two methods:
    First:
    CDatabase Db;
    Db.Open();//add arguments here
    Db.ExcuteSQL(strSQL);Second:
    CRecordset Rs;
    Rs.m_pDatabase = &Db; 
    Rs.Open(strSQL);
      

  2.   

    CDatabase database;
    database.Open(_T( "MyPOSDB" ),false,false,_T( "ODBC;UID="));
    CRecordset recset( &database );
    SqlString =  "SELECT * FROM Item order by item_nbr"; recset.Open(CRecordset::forwardOnly, SqlString,CRecordset::readOnly); while( !recset.IsEOF() )
    {
    // Copy each column into a variable
    recset.GetFieldValue("item_nbr",sCatID);
    recset.GetFieldValue("item_desc",sCategory);
    iRec = m_ListControl.InsertItem(i,sCatID,0);
    m_ListControl.SetItemText(i,1,sCategory);
    m_ListControl.SetItemText(i,2,cstrPrice);
    i ++;
    recset.MoveNext();
    }
    database.Close();
      

  3.   

    这是我的部分代码:
    UpdateData(1);
        m_database.Open(_T("sql"));
        m_user.Format("select * from book where Title='%s'",m_Title);
        CFinalSet *newTable=new CFinalSet(&m_database);
        newdb->Open(AFX_DB_USE_DEFAULT_TYPE,m_user);
        m_Title=newTable->m_Title;
    m_Author=newTable->m_Author;
        m_Publisher=newTable->m_Publisher;
        m_PublishTime=newTable->m_PublishTime;
        m_Style=newTable->m_Style;
        m_BookNum=newTable->m_BookNum;大家看的出来这是个查询部分,问题是那个SQL语句,使我只能对输入的m_Title值查询,但是我想当输入m_Author,m_Publisher,...的时候都可以进行查询,我不知道应该怎么做,还请大家再帮帮忙.
      

  4.   

    建议用ADO,网上有很现成的例子。ADO学起来比较简单。