//***************************************************************************
BOOL CBCGPDAOGridCtrl::GetFieldList (LPCTSTR lpszTable, CStringList& lstField)
{
	ASSERT (lpszTable != NULL);

	lstField.RemoveAll ();

	try
	{
		if (m_pDataBase == NULL)
		{
			ASSERT (FALSE);
			return FALSE;
		}

		ASSERT_VALID (m_pDataBase);

		if (!m_pDataBase->IsOpen ())
		{
			ASSERT (FALSE);
			return FALSE;
		}

		CDaoRecordset* pRecordSet = new CDaoRecordset (m_pDataBase);

		CString strSQL = _T("SELECT * FROM ");
		strSQL += lpszTable;

		pRecordSet->Open (AFX_DAO_USE_DEFAULT_TYPE, strSQL);

		if (!pRecordSet->IsOpen ())
		{
			delete pRecordSet;
			return FALSE;
		}

		const short nColumns = pRecordSet->GetFieldCount ();

		for (short nColumn = 0; nColumn < nColumns; nColumn++)
		{
			CDaoFieldInfo info;
			pRecordSet->GetFieldInfo (nColumn, info);

			lstField.AddTail (info.m_strName);
		}

		pRecordSet->Close ();
		delete pRecordSet;
	}
	catch (CDaoException* pEx)
	{
		OnDaoException (pEx);
		pEx->Delete ();

		return FALSE;
	}

	return TRUE;
}
int GetFieldPos(CDaoRecordset& recs, LPCTSTR fieldName)
{
	CDaoFieldInfo fi;
	int count = recs.GetFieldCount();

	for( int i = 0; i < count; i++ )
	{
		recs.GetFieldInfo(i, fi);
		if( fi.m_strName.Compare( fieldName ) == 0 )
			return i; // when found a match, return it
	}

	return -1;
}