Add field with Boolean field type failed using ADOX

Add field with Boolean field type failed using ADOX

Post by Debbi » Thu, 28 Sep 2000 04:00:00



The following code works for Text, integer field type,  but I got
Dispatch error if the field type is adBoolean,  why??

thx, Debbie

   TESTHR(hr = pCnn.CreateInstance(__uuidof(ADODB::Connection)));
   TESTHR(hr = pCatalog.CreateInstance(__uuidof (Catalog)));
   TESTHR(hr = pColumn.CreateInstance(__uuidof (Column)));
   // Connect the catalog.
   pCnn->Open (strCnn, "", "", NULL);
   pCatalog->PutActiveConnection(variant_t((IDispatch *)pCnn));

   pColumn->Attributes = (ColumnAttributesEnum)(adColNullable);
   pColumn->PutName(_bstr_t(dlg.m_nameRet));
   pColumn->PutType(ADODataTypeEnum(dlg.m_typeRet));  file://ADODataTypeEnum
   long size = 0;
   if(dlg.m_typeRet >= 200 && dlg.m_typeRet <= 203)
       size = dlg.m_sizeRet;
   pColumn->DefinedSize = size;
   pTable = pCatalog->Tables->
           GetItem(_variant_t(m_tablename));
   pTable->Columns->Append(variant_t((IDispatch*)pColumn),
    ADODataTypeEnum(dlg.m_typeRet), size);
   pCatalog->Tables->Refresh();
   pCatalog = NULL;
   pCnn->Close();

 
 
 

1. Failed to add Boolean type field to Access table using ADOX

Hi I am using VC++/ADO/ADOX/Access, I have successfully append the field
with text, integer, double and even datetime type.  But I got Dispatch error
if I add a ADODB::adBoolean type,  what is wrong?
I was totally confused.  The code is attached as following, thank you for
your time!

Debbie

.......
InputFieldDlg dlg;  // input field name, type and size if it is Text field
dlg.DoModal();
try
{
   TESTHR(hr = pCnn.CreateInstance(__uuidof(ADODB::Connection)));
   TESTHR(hr = pCatalog.CreateInstance(__uuidof (Catalog)));
   TESTHR(hr = pColumn.CreateInstance(__uuidof (Column)));
   // Connect the catalog.
   pCnn->Open (strCnn, "", "", NULL);
   pCatalog->PutActiveConnection(variant_t((IDispatch *)pCnn));

   pColumn->Attributes = (ColumnAttributesEnum)(adColNullable);
   pColumn->PutName(_bstr_t(dlg.m_nameRet));
   pColumn->PutType(ADODataTypeEnum(dlg.m_typeRet));
   long size = 0;
   if(dlg.m_typeRet >= 200 && dlg.m_typeRet <= 203)  // text field?
       size = dlg.m_sizeRet;
   pColumn->DefinedSize = size; // 0 for other field type
                                // for boolean type, I have tried 0,1,2 all
failed
   pTable = pCatalog->Tables->GetItem(_variant_t(m_tablename));
   pTable->Columns->Append(variant_t((IDispatch*)pColumn),
                            ADODataTypeEnum(dlg.m_typeRet), size);     //
<----failed
   pCatalog->Tables->Refresh();
   pCatalog = NULL;
   pCnn->Close();
catch(_com_error& e)
{
    ......

2. Raw Partitions vs. File Systems (an Old debate)

3. Create boolean field using ADOX

4. Instance manager NLS error

5. To add a field of the type Dates with a field of the Whole type

6. Help Help help Building Form with Noramalized data.

7. Adding a field to the field-definitions using Diamond Access

8. ODBC wont work on mapped NT drive.

9. Type Mismatch when Adding Matching Type Decimal Fields

10. Adding a boolean field

11. addnew with boolean field fails-Access 2000 ADO RDS

12. Setting boolean field from date field values...

13. Adding a new field to an existing table via ADOX