Hi Jim,
Thank you for posting in the community! My name is Kevin, and I will be
assisting you on this issue.
First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get the information about
if the column is auto increment with ADO.NET. If there is any
misunderstanding, please feel free to let me know.
As far as I know, ADO.NET cannot get auto increment information from an
OleDbConnection, because the auto increment is not supported by all
databases. Just as Paul mentioned, we can use ADOX or DAO to achieve this.
Microsoft ActiveX Data Objects Extensions for Data Definition Language and
Security (ADOX) is an extension to the ADO objects and programming model.
ADOX includes objects for schema creation and modification, as well as
security. We can use it to manipulate on the schema of a database. Here I
have written a short example of how to determine whether a column in auto
increment using VB.NET. Since the ADOX.Catalog requires an active
connection, we have to reference both ADO and ADOX libraries. Here are the
steps:
1. Create a new VB.NET project.
2. Select Project / Add Reference... from the menu.
3. Double click to select adodb from the .NET tab. (adodb is the Primary
Interop Assemblies of ADO library.) And select Microsoft ADO Ext. 2.7 for
DLL and Security in the COM tab. (Assume that you have MDAC 2.7 installed
on your computer.)
4. The following is the code. It will go through each column in the column
collection if the column is auto increment, a message box will pop up.
Dim cnn As ADODB.Connection = New ADODB.ConnectionClass
Dim cat As ADOX.Catalog = New ADOX.CatalogClass
Dim tbl As ADOX.Table
Dim col As ADOX.Column
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\db3.mdb;Persist Security Info=False"
cnn.Open()
cat.ActiveConnection = cnn
tbl = cat.Tables("Table1")
For Each col In tbl.Columns
If col.Properties("AutoIncrement").Value = True Then
MessageBox.Show("auto inc")
End If
Next
End Sub
Hope this helps.
Does this answer your question? If anything is unclear, please feel free to
reply to the post.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."