You should create at least 3 CRecordsets -- one for table1, one for table2 and one for the joined table1+table2 (based on primary and foreign keys).
That way, you can use (insert, update, delete, select) for each table individually or you can just read the combined/joined table.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
Use the class wizard to create an Odbc Recordset class.
Use the SQL inside of the class to reference both tables.
In the GetDefaultSQL() function, put the names of both the tables if you did not select them in the wizard.
CString CLmSubProfileByEsn::GetDefaultSQL()
{
return _T("[MAPS].[NAMES], [MAPS].[ADDRESS]"); // ** <<< TWO TABLES
}
put the WHERE clause in the m_strFilter in the constructor:
m_strFilter =_T("NAMES.ADDRESS_ID=ADDRESS.ADDRESS_ID AND NAME=?");
...and the columns go in the DoFieldExchange including any SQL parameters.
void CClassName::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CLmSubProfileByEsn)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Text(pFX, _T("[NAME]"), m_NAME);
RFX_Text(pFX, _T("[ADDRESS]"), m_ADDRESS);
//}}AFX_FIELD_MAP
pFX->SetFieldType(CFieldExchange::param);
RFX_Text(pFX, _T("NAME"), m_NAME);
}
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
Yes, but remember to register your database in the ODBC Administrator.
[somewhere like]:
Control Panel->Administrative Tools->DataSources (ODBC) / System DSN
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402