473,805 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8238
you need to read the DB schema - plenty examples on goolge

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"mwn" <mw*@discussion s.microsoft.com > wrote in message
news:8E******** *************** ***********@mic rosoft.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*@discussion s.microsoft.com > ha scritto nel messaggio
news:8E******** *************** ***********@mic rosoft.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 (myConnectionSt ring);
DataTable dtColumn;
cn.Open();

All columns, all tables
dtColumn = cn.GetOleDbSche maTable(OleDbSc hemaGuid.Column s,new Object[]
{null, null, null, null});

All coluns, table "Tabe1"
dtColumn = cn.GetOleDbSche maTable(OleDbSc hemaGuid.Column s,new Object[]
{null, null, "Tabe1", null});

Column "myCol", All Tables
dtColumn = cn.GetOleDbSche maTable(OleDbSc hemaGuid.Column s,new Object[]
{null, null, null, "myCol"});


Nov 16 '05 #3
"mwn" <mw*@discussion s.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_maxim um_length
FROM information_sch ema.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*@discussion s.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_maxim um_length
FROM information_sch ema.columns
WHERE table_name = 'SomeTable'

P.

Nov 16 '05 #5
mwn
SOLUTION FOUND
Essence of it is:
OleDbDataReader reader = comm.ExecuteRea der (CommandBehavio r.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*@discussion s.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_maxim um_length
FROM information_sch ema.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
2764
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 of similar web pages for each table I'm looking into recording metadata about tables / columns in the database and using this to determine presentation. Let's keep things simple for now and assume that I'm interested in adding more user friendly...
3
2408
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 'ReadOnly'" on the line that SHOULD be turning this property on for the ID field. Does any one have any suggestions on how to do this in .NET? The code that I am using is: Dim cat As Catalog = New Catalog Dim tblNew As ADOX.Table = New...
7
2840
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 of custom, extended nodes, which include all the extra information contained in the table and not just typical TreeNode objects. To do that, I first created a structure with all the extra
6
9182
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 Property 'item' is ReadOnly error within the below line .Columns("ContactId").Properties("AutoIncrement") = True Am I missing a reference or what am I doing wrong?????
1
3470
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 Dim tbl As ADOX.Table Dim idx As ADOX.Index Dim prp As ADOX.Property
17
1524
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 any ADODB or ADOX stuff. What I'm trying to do is retrieve all the properties of all the components of a database. The GetSchema method goes a long way but (so far) I'm missing how to get the default value of a column. In the table that's returned...
4
5758
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 additional properties...while you might need only one property for another product, e.g litres for a soft drink...so I was thinking of creating a properties table, a units table and a product table, properties-unit table... and...
4
3517
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 rows are being read and inserted into the table. The problem is that one of the columns in the CSV contains the value of 1 thru 6 or C, BUT only the numbers seem to be read into the DataTable not the letter. I tried single quotes and double quotes...
1
3704
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 a form in MS Access, on that form, I have 2 buttons & a text box. One button is to select a mdb file, whom properties i want to display. Second button then stores that properties in a Excel file. when I open the file using first button, the path of...
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10614
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.