473,418 Members | 2,028 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,418 software developers and data experts.

Getting table schema information with ADO.NET

Given a table name (e.g. CUSTOMERS), how do I get column names of the table
and the data types of the columns the table has?

I am using SQLServer and would like to get that info from my C# code.
Nov 17 '05 #1
3 8981
"Jason Manfield" <Ja***********@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Given a table name (e.g. CUSTOMERS), how do I get column names of the
table
and the data types of the columns the table has?

I am using SQLServer and would like to get that info from my C# code.


I am sure there are more elegant ways, but you could always read "EXEC
sp_help '<tablename>'" into an SqlDataReader and look at the second
Resultset... See BOL for further info on sp_help
Nov 17 '05 #2
Use the INFORMATION_SCHEMA views to access the schema information:

SELECT
COLUMN_NAME,
DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Customers'

This will return all the column names, data type and length for character
data, one row per column.

I hope this helps,

Jon

"Jason Manfield" <Ja***********@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Given a table name (e.g. CUSTOMERS), how do I get column names of the
table
and the data types of the columns the table has?

I am using SQLServer and would like to get that info from my C# code.

Nov 17 '05 #3
You can use the GetSchemaTalbe method of a SqlDataReader or loop through a
DataTable that's been filled with an Adapter.

http://www.knowdotnet.com/articles/g...hematable.html
should help

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Jason Manfield" <Ja***********@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Given a table name (e.g. CUSTOMERS), how do I get column names of the table and the data types of the columns the table has?

I am using SQLServer and would like to get that info from my C# code.

Nov 17 '05 #4

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

Similar topics

2
by: Developer98115 | last post by:
I need help getting schema information from an existing SQL Server database. My thought was that you could use ADOX via InterOp. Has anyone done this successfully and how? I have created a...
6
by: Wei Shi | last post by:
Hi, does anyone know how to get the schema information of a table. More specifically, I would like to know 1. which field(s) are primary keys? 2. the data type of each field of a table? 3. If...
13
by: N. Graves | last post by:
Thanks for taking time to read my questions. I'm looking for a way in Access that I could run a query that would return table schema information. Specifically I need to get the column name,...
0
by: Derek | last post by:
I am creating an intranet using Visual Web Developer Express Edition. Everything has been working OK until yesterday when I started getting 62 messages all beginning "Could not find schema...
0
by: jhansen | last post by:
I am getting informational warnings about the following app.config and indicate the following. I am using C# visual studio 2005 and used the Settings.settings to set up my values scoped as...
3
by: JPS | last post by:
Does anyone know how to query a table and get the schema informationback as well as the values in the fields. Here is what I have done so far. I cannot get both. using (SqlConnection conF =...
3
by: visu | last post by:
Hi , can anyone tell me how to get the complete table schema including constraints, primary key ..etc. through sql Query in Ms access. We can get table information in MS SQL Server by means...
22
by: klenwell | last post by:
I'm in the process of refactoring the php code base I've amassed over the last few years into an object-oriented framework. I'm about to start in on the authentication/login extension and I've...
13
by: amit2781 | last post by:
How can we get the table schema information in MYSQL 5.1.34? Like we use in ORACLE to get it as: OCIDescribeAny() // //get the describe handle for the table to be described. OCIAttrGet() ...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
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...
0
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...

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.