How to get datatype of a column in SQL Server using c#? [Resolved]

Posted by Shameer.Ali87 under C# on 3/26/2013 | Points: 10 | Views : 9639 | Status : [Member] | Replies : 6
hi all,

How to get a datatype of a column, present in table of a sql server..?
any Query/links will be help full...

thanks

shameer ali shaik


Responses

Posted by: Jayakumars on: 3/26/2013 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
hi

try this procedure working good

Exec sp_FindDatatype 'Employee'

CREATE Proc sp_FindDatatype
@TblName varchar(50)
as
SELECT COLUMN_NAME,DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=@TblName


Donot Forgot mark as answer if it is useful to u.

Mark as Answer if its helpful to you

Shameer.Ali87, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 3/26/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
exec sp_columns Tablename

If this post helps you mark it as answer
Thanks

Shameer.Ali87, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santhi on: 3/26/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

Refer this link:
This may help you:
http://stackoverflow.com/questions/7470258/how-to-get-the-sqltype-of-a-column-in-a-datatable

Thanks & Regards,
Santhi .V

Shameer.Ali87, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shameer.Ali87 on: 3/26/2013 [Member] Starter | Points: 25

Up
0
Down
thanks Jayakumar,
your answer worked for me..

I made a slight change as below,
SELECT data_type FROM information_schema.columns WHERE table_name = 'T1' AND column_name = 'C1'

keep going..
thanks




shameer ali shaik

Shameer.Ali87, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/26/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

Welcome Shameer share with your knowledge here.


Mark as Answer if its helpful to you

Shameer.Ali87, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jitendrasoft09 on: 3/27/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
There are following code to get datatype of a column in SQL Server using c# code, first need to create DataTable which corresponds to sql server table.
string dbtype = datatable.Columns[0].DataType.ToString();

Jitendra Kumar
If my post helps you, plz mark as an answer.

Shameer.Ali87, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response