Click to See Complete Forum and Search --> : Error while retrieving data with CRecordSet


Anand Sawant
May 25th, 1999, 03:56 AM
Dear all,

I am creating a MFC dialog based application in VC++ 6.0.
Database is MS-Access.
Driver is ODBC.
Platform: WIN NT.

Description of my table is as follows.

Table Name - Machine

Machine ID (Primary key)- Number
Machine Name - Text
Machine Type - Text
Clamping Tonnage - Number
Injection Force - Number

StdMachineSet is the object of class derived from CrecordSet.

StdMachineSet.Open(CRecordset::dynaset,
"SELECT DISTINCT [Machine Name] FROM Machine",
CRecordset::readOnly);

It gives me the error : Error retreiving record.

When I changed the query to

StdMachineSet.Open(CRecordset::dynaset,
"SELECT * FROM Machine",
CRecordset::readOnly);

It works fine.

What might be the problem?

Regards,

Anand.

Peter Hendén
May 25th, 1999, 06:29 PM
Just off the top of my head:

SELECT DISTINCT returns a static recordset. If you try

CRecordset::snapshot instead of CRecordset::dynaset

your query might succeed.

HTH,
Peter

Anand Sawant
May 25th, 1999, 11:14 PM
Hi Peter,
It didn't work with CRecordset::snapshot also.
Anand.

Peter Hendén
May 26th, 1999, 02:14 AM
OK,

How does your DoFieldExchange function look?

Regards,
Peter

Anand Sawant
May 26th, 1999, 04:34 AM
void CMachineSet::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CMachineSet)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Int(pFX, _T("[MachineID]"), m_MachineID);
RFX_Text(pFX, _T("[Machine Name]"), m_Machine_Name);
RFX_Text(pFX, _T("[Machine Type]"), m_Machine_Type);
RFX_Double(pFX, _T("[Clamping Tonnage]"), m_Clamping_Tonnage);
RFX_Double(pFX, _T("[Injection Force]"), m_Injection_Force);
//}}AFX_FIELD_MAP
}

Regards,
Anand.

Peter Hendén
May 26th, 1999, 08:01 AM
There's the problem: You have only the [Machine Name] field in your recordset. The Field exchange function expects all the fields of your table.

Regards,
Peter