Using MFC, CRecordset class running a select query for a particular table in the Database.
Posted on 2005-04-15
I am using Crecordset class wizard & I have recordset class for every table in the database. for eg: I have a table named "SPECIMEN" & by using the wizrad i have a class named CSPECIMEN
consider my recordset class as follows:CSPECIMEN* pSpecimen=new CSPECIMEN(m_db);
So I have already opened the database with m_db & then
//pSpecimen->m_strFilter="Part_Number= '"+ m_Part_Number +"' ";
pSpecimen->m_strFilter="Part_Number ='" + m_strPart_Number +"' AND Serial_Number= '"+ m_strSerial_Number +"'";
pSpecimen->Open( CRecordset::snapshot,_T( "Select * from Specimen " ));
This query works great with all the results, Now I want to run this query _T("Select DISTINCT Serial_Number from Specimen");
it fails, error in the query,,,so I just want to run a simple query _T("Select Serial_Number from Specimen");that fails.
I think the CSPECIMEN::GetDefaultSQL() & void CSPECIMEN::DoFieldExchange(CFieldExchange* pFX) in the class needs to be altered so that it runs, presently the function is as follows:
void CSPECIMEN::DoFieldExchange(CFieldExchange* pFX)
// Macros such as RFX_Text() and RFX_Int() are dependent on the
// type of the member variable, not the type of the field in the database.
// ODBC will try to automatically convert the column value to the requested type
RFX_Date(pFX, _T("[Specimen_ID]"), m_Specimen_ID);
RFX_Text(pFX, _T("[Part_Number]"), m_Part_Number);
RFX_Text(pFX, _T("[Serial_Number]"), m_Serial_Number);
RFX_Text(pFX, _T("[Cycle_Number]"), m_Cycle_Number);
RFX_Long(pFX, _T("[UT_History_Count]"), m_UT_History_Count);
So what should I change so that I can run any select queries?