Solved

I need to capture what SQL datatypes are being returned.

Posted on 2011-03-14
9
267 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 200 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

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 150 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 150 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

726 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