开发者

How to get the auto-increment column from a table of MS Access Database using ADO and C++?

开发者 https://www.devze.com 2022-12-10 12:02 出处:网络
I have used the following way to determine if a column is auto-increment: att = Rs1->Fields->Get开发者_StackOverflowItem((long)nIndex)->Attributes;

I have used the following way to determine if a column is auto-increment:

att = Rs1->Fields->Get开发者_StackOverflowItem((long)nIndex)->Attributes;
bAutoIncrement = att & adFldRowID;

But it doesn't work at all. Do anyone have good ideas about this? Thanks in advance.


Dim ADOXCatalog As New ADOX.Catalog
Dim ADOConnection As New ADODB.Connection

Try
ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\db1.mdb;" & _
"Jet OLEDB:Engine Type=4;")

ADOXCatalog.ActiveConnection = ADOConnection

Dim col As ADOX.Column
For Each col In ADOXCatalog.Tables("Table1").Columns
If col.Properties("AutoIncrement").Value = True Then
Console.WriteLine(col.Name)
End If
Next

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
ADOConnection.Close()
End Try


Use This:

try{
    ADOX::_CatalogPtr pCatalog= NULL;
    pCatalog.CreateInstance(__uuidof(ADOX::Catalog));
    pCatalog->PutActiveConnection( _variant_t( (IDispatch*)m_ipConnection ) );
    bool v = pCatalog->Tables->GetItem(bstrTableName)->Columns->GetItem(L"PlaceholderForAutoIncrementFieldName")->Properties->GetItem("AutoIncrement")->Value;
    return v;
}
catch(_com_error &e)
{
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());

    TRACE("\n\tSource :  %s \n\tdescription : %s \n ", (LPCSTR)bstrSource, (LPCSTR) bstrDescription);
}   


ADOX::PropertyPtr pAutoIncrProperty = m_pTable->Columns->Item[_variant_t(fieldInfo.m_strName)]->Properties->Item[_variant_t(_T("AutoIncrement"))];

0

精彩评论

暂无评论...
验证码 换一张
取 消