473,396 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Read database column properties

mwn
In a C# WinApp how do I display column properties?
For example, I want to display from pubs.employee all columns and properties
ColumnName DataType Length Precision Scale Default Value Collation
emp_id char 9 0 0
fname varchar 20 0 0
hire_date datetime 8 0 0 (getdate())

Probably very simple but have not found any examples.
--
m nabarro
Nov 16 '05 #1
5 8209
you need to read the DB schema - plenty examples on goolge

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"mwn" <mw*@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
In a C# WinApp how do I display column properties?
For example, I want to display from pubs.employee all columns and properties ColumnName DataType Length Precision Scale Default Value Collation
emp_id char 9 0 0
fname varchar 20 0 0
hire_date datetime 8 0 0 (getdate())

Probably very simple but have not found any examples.
--
m nabarro

Nov 16 '05 #2

"mwn" <mw*@discussions.microsoft.com> ha scritto nel messaggio
news:8E**********************************@microsof t.com...
In a C# WinApp how do I display column properties?
For example, I want to display from pubs.employee all columns and
properties
ColumnName DataType Length Precision Scale Default Value Collation
emp_id char 9 0 0
fname varchar 20 0 0
hire_date datetime 8 0 0 (getdate())

Probably very simple but have not found any examples.
--
m nabarro


OleDbConnection cn = new OleDbConnection(myConnectionString);
DataTable dtColumn;
cn.Open();

All columns, all tables
dtColumn = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,new Object[]
{null, null, null, null});

All coluns, table "Tabe1"
dtColumn = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,new Object[]
{null, null, "Tabe1", null});

Column "myCol", All Tables
dtColumn = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,new Object[]
{null, null, null, "myCol"});


Nov 16 '05 #3
"mwn" <mw*@discussions.microsoft.com> wrote:
In a C# WinApp how do I display column properties?


If this is SQL Server, you can retrieve metadata with a query:

SELECT column_name, data_type, column_default,
character_maximum_length
FROM information_schema.columns
WHERE table_name = 'SomeTable'

P.
Nov 16 '05 #4
mwn
P

This is helpful in one sense. Using this in a Stored Procedure would be neat.
However, I was seeking a generic solution that would work with Informix,
Oracle, MSSQL and other ODBC sources. All the many GetOleDbSchema examples
(simple) seem to get a far as the column name but never go that final step to
reveal the likes of a column's max length, scale, precision and other
attributes.

Thank you for taking the time to offer a solution.

"Paul E Collins" wrote:
"mwn" <mw*@discussions.microsoft.com> wrote:
In a C# WinApp how do I display column properties?


If this is SQL Server, you can retrieve metadata with a query:

SELECT column_name, data_type, column_default,
character_maximum_length
FROM information_schema.columns
WHERE table_name = 'SomeTable'

P.

Nov 16 '05 #5
mwn
SOLUTION FOUND
Essence of it is:
OleDbDataReader reader = comm.ExecuteReader (CommandBehavior.SchemaOnly);

"mwn" wrote:
P

This is helpful in one sense. Using this in a Stored Procedure would be neat.
However, I was seeking a generic solution that would work with Informix,
Oracle, MSSQL and other ODBC sources. All the many GetOleDbSchema examples
(simple) seem to get a far as the column name but never go that final step to
reveal the likes of a column's max length, scale, precision and other
attributes.

Thank you for taking the time to offer a solution.

"Paul E Collins" wrote:
"mwn" <mw*@discussions.microsoft.com> wrote:
In a C# WinApp how do I display column properties?


If this is SQL Server, you can retrieve metadata with a query:

SELECT column_name, data_type, column_default,
character_maximum_length
FROM information_schema.columns
WHERE table_name = 'SomeTable'

P.

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Daniel M | last post by:
I'm building a medium-scale data-entry web application, which involves creating data entry forms, record listings and detail screens for lots of database tables. Rather than designing a series...
3
by: Eric Carr | last post by:
I have been trying to create a table in an Access database via a VB.NET program and I am running into a problem defining an autoincrement field. I am getting an error saying "Property 'Item' is...
7
by: vsiat | last post by:
I am trying to create a treeview out of a database table with the typical structure ID, NAME, PARENTID, TYPE, EXTRA_INFO, where is linked to the . What I want to achieve is create a tree made...
6
by: Michael | last post by:
I am trying to create an access database within Net 2003 using the ADOX library which works fine except when I try to add the AutoIncrement property to the ContactId column. I am experiencing a...
1
by: sunlight_sg | last post by:
Hello, i am using ADOX + VB .NET to create a Access Database programmatically. I plan to set some properties of the column such primary key. The code is as follows: Dim cat As ADOX.Catalog...
17
by: Sam Malone | last post by:
I am trying to get details from a database. I really want to use only native VS.NET managed code "stuff" (just cuz I want to) and avoid any interop stuff. So, I'm trying to do this without using...
4
by: beatdream | last post by:
I am designing a database to handle different kinds of products ... and these products can have different properties...for example, a trouser can be specified by the width, length, color, and other...
4
by: =?Utf-8?B?TWlrZSBE?= | last post by:
I read the CSV file into a DataTable. This is so I can fix invalid dates and other data I don't want in the database. Then I use SqlBulkCopy to insert the data into the SQL database. All the...
1
by: sunnyluthra1 | last post by:
Hi Everyone, I am working on a piece of code, that displays the properties(Name, Datatype, size & Description) of the table in the database. Now I want to further Enhance the code. I Have created...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.