Field Existence with ADO
Database
2
Posts
2
Posters
4
Views
1
Watching
-
Hi, I was wondering if there was any way I could check for the existence of a field in a table without poking the database and handling an error. I'm sure there is a way, but all my searching has led to no avail.:confused:
use the FieldsPtr class e.g.
FieldsPtr ptrFields = NULL;
FieldPtr ptrField = NULL;// assign the Fields that we have from the recordset
ptrFields = m_pRS->Fields;
int nCols = ptrFields->Count;FieldPtr ptrField = NULL;
_variant_t vCol((long)-1);
for (int i = 0; i < nCols; i++)
{
vCol.lVal = i;
HRESULT hr = ptrFields->get_Item(vCol, &ptrField);
if(FAILED(hr))
_com_issue_error(hr);// now check if the field exist
if ((LPCSTR)ptrField->Name == "My Field")
{
// Do Something
}
}:cool: