Querying Access database table column definitions for Default Value and Index

J Trahair

Well-known member
Joined
May 14, 2008
Messages
175
Location
Spain
Programming Experience
10+
I am trying to query an Access database table to get information about each column eg. Default Value (in a numeric field usually 0 but not always), and whether a column is indexed (eg. Yes (Duplicates OK)). I am using the following code to get some of the information - I just need these two now.

VB.NET:
objDs1.Tables(0).Columns(numColNo).DataType.ToString
gives me the field data type eg. System.String etc., that's good.

but
VB.NET:
objDs1.Tables(0).Columns(numColNo).DefaultValue
for Long and Double gives me minus 1 or blank every time, which is not the Default Value.

What should I do?

Thanks in advance.
 
You would call the OleDbConnection.GetSchema method to get that sort of information. You can also call GetOleDbSchemaTable, which will provide some slightly different information. You'd call it with no arguments first, to determine what collections are available to query, then pass the appropriate arguments to query the appropriate collections. Start by reading the MSDN documentation for those methods.
 
Back
Top