Discussion Locked

retrieve column default via ADO

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
In SQL Server, I have a default defined on a column in a table. Is there a way to find out via ADO what that default is? I can't find any properties on the Field object that would tell me. Is it somewhere else?

2 replies

by shanghai sam

You won't be able to retrieve that value in the ADODB.Recordset that way. The default value is something the db adds when an insert is done on that table, and it doesn't "carry" the value around. You can get the default value through the system tables in SQL Server (see the syscolumns table)--this might be more JOINs than you care to do, but it's there.

by Lamont Adams

ADO has to know this information in order to be able to perform disconnected updates, the question is whether you can get at it or not.

I'd try using the OpenSchema method of your connection and pass the adSchemaColumns constant into it along with a variant array containing the name of a catalog, schema and table.

OpenSchema returns a recordset representing properties of whatever object you specify. In your case, each column in your table would be a record in the recordset. One of the fields in the returned recordset should hold the default value for column represented by that record.

Here's a KB article with some more information: http://support.microsoft.com/support/kb/articles/Q186/2/46.ASP

Hope that helps, and thanks for using TechRepublic!

This discussion is closed to new replies.