CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: MFC SQL join

  1. #1
    Join Date
    Jul 1999
    Posts
    16

    MFC SQL join

    I am trying to use the MFC ODBC database classes to solve a particular problem. However, knowing only the basics, I am unable to figure out how to implement a recordset for SQL statements that will contain a "join" command. For example, I need to implement the statement:

    select count(nameid), max(currentdate)
    from events join eventday on events.dayid = eventday.dayid
    group by eventday.dayid
    order by eventday.dayid

    This joins the tables "events" and "eventday". What is the procedure for doing something like this using MFC?

    Thanks in advance.


  2. #2
    Join Date
    Sep 1999
    Location
    Europe / Austria / Innsbruck
    Posts
    442

    Re: MFC SQL join

    Hi. To execute SQL statements without deriving a new class from CRecordset, you can call CRecordset itself by supplying the SQL statement:

    CRecordset set(pDatabase);
    CString strSelect = "SELECT SUM(Field1) FROM TestTable", strValue;

    set.Open(CRecordset::forwardOnly, strSelect, CRecordset::readOnly |
    CRecordset::noDirtyFieldCheck | CRecordset::executeDirect);
    set.GetFieldValue(0, strValue); // use GetFieldValue to get the field values, because
    double dSum = atof(strValue); // we haven't derived a class with member variables
    set.Close();





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured