?
Solved

I need to capture what SQL datatypes are being returned.

Posted on 2011-03-14
9
Medium Priority
?
268 Views
Last Modified: 2013-12-17
I am returning a dataset from a SQL 2005 stored procedure.

I need to capture what SQL datatypes are being returned.

For example. Column1 = Varchar(10), Column2 INT.

Is this possible?
0
Comment
Question by:Mr_Shaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 12

Expert Comment

by:enachemc
ID: 35127496
use the metadata of the returned resultset
0
 

Author Comment

by:Mr_Shaw
ID: 35127522
how what I do that?
0
 
LVL 11

Accepted Solution

by:
Kusala Wijayasena earned 800 total points
ID: 35127525

I don't think there is 1 to 1 map between SQL data types and CLR data type. But there is a standard mapping that you could use

http://msdn.microsoft.com/en-us/library/ms131092.aspx

-Kusala
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Mr_Shaw
ID: 35127527
My dataset is populated from a stored procedure.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35127610
The schema that comes with the DataTable will only give the the CLR type that your columns map to, it won't return you the underlying SQL data type.
0
 

Assisted Solution

by:BlueKarana
BlueKarana earned 600 total points
ID: 35127615
This is the SQL for querying metadata (data about the data) in SQL Server:

SELECT     TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION, COLUMN_DEFAULT, IS_NULLABLE, DATA_TYPE, 
                      CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_PRECISION_RADIX, NUMERIC_SCALE, DATETIME_PRECISION, 
                      CHARACTER_SET_CATALOG, CHARACTER_SET_SCHEMA, CHARACTER_SET_NAME, COLLATION_CATALOG, COLLATION_SCHEMA, COLLATION_NAME, 
                      DOMAIN_CATALOG, DOMAIN_SCHEMA, DOMAIN_NAME
FROM         INFORMATION_SCHEMA.COLUMNS
WHERE     (TABLE_NAME = '[your table name]')

Open in new window


You can see that one of these is DATA_TYPE, which is what you're after.
0
 
LVL 7

Assisted Solution

by:mkobrin
mkobrin earned 600 total points
ID: 35127629
if you have named your data reader "reader" then this will work for you:

                                    int counter = reader.FieldCount;
                                    for (int k= 0; k< counter; k++)
                                    {
                                        string type = reader[ki].GetType().ToString();
                                    }
0
 

Author Comment

by:Mr_Shaw
ID: 35128127
GetType() returns System.Data.DataColumn
0
 

Author Closing Comment

by:Mr_Shaw
ID: 35128278
thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question