Obtaining column properties in .NET

  • Thread starter Thread starter schneider
  • Start date Start date
S

schneider

Hi all,

I want to obtain column properties using C# and the System.Data
namespace. Using DbDataReader.GetSchemaTable() or DataAdapter.Columns
I only retrieve properties like DataColumn.MaxLength or
DataColumn.AllowDbNull in a correct fashion. But if I want properties
like DefaultValue or certain column validation rules, I fail. Does
anyone know how to obtain these values? If so, please post some sample
code or links.
Thank you very much in advance.

Regards,
Hannes
 
Hi all,

I want to obtain column properties using C# and the System.Data
namespace. Using DbDataReader.GetSchemaTable() or DataAdapter.Columns
I only retrieve properties like DataColumn.MaxLength or
DataColumn.AllowDbNull in a correct fashion. But if I want properties
like DefaultValue or certain column validation rules, I fail. Does
anyone know how to obtain these values? If so, please post some sample
code or links.

Please don't crosspost questions to both .data.ado (a classic ado group) and
..dotnet.framework.adonet. Most questions will be relevant in only one of
those groups. In this case, only the adonet group is relevant.

That said, most databases have system tables or views from which you can get
this information. Please specify the database you are using.

Followup-To set to microsoft.public.dotnet.framework.adonet
 
On Fri, 19 Oct 2007 03:01:52 -0700, (e-mail address removed) wrote:

¤ Hi all,
¤
¤ I want to obtain column properties using C# and the System.Data
¤ namespace. Using DbDataReader.GetSchemaTable() or DataAdapter.Columns
¤ I only retrieve properties like DataColumn.MaxLength or
¤ DataColumn.AllowDbNull in a correct fashion. But if I want properties
¤ like DefaultValue or certain column validation rules, I fail. Does
¤ anyone know how to obtain these values? If so, please post some sample
¤ code or links.
¤ Thank you very much in advance.

The generic method, which relies on functionality supported by the OLEDB provider, is
GetOleDbSchemaTable.

HOW TO: Retrieve Meta Data from Excel by Using GetOleDbSchemaTable in Visual C# .NET
http://support.microsoft.com/kb/318452/zh-cn

Keep in mind that database specific implementations will likely require alternative methods.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Please don't crosspost questions to both .data.ado (a classic ado group) and
.dotnet.framework.adonet. Most questions will be relevant in only one of
those groups. In this case, only the adonet group is relevant.

That said, most databases have system tables or views from which you can get
this information. Please specify the database you are using.

Followup-To set to microsoft.public.dotnet.framework.adonet
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Hi,

first, sorry for cross-posting. I'll try to remind this in the future.
My goal is to use an Access database as schema template for
customizing another database which can be Access again or Microsoft
SQL Server, Oracle, MySQL, ... For example if a new column is
introduced with the template database, this column should be applied
to all other databases including DefaultValue and other properties.
I'm aware that not all Access database features will be supported in
the other database applications, but e.g. Default Values will.
I need to obtain this column schema and apply it to columns in the
"child databases".
Thanks again in advance for your help.

Regards,
Hannes
 
Back
Top