Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,
I need to determine the type of a column selected from dropdown list from a SQL Server database using C#.

my question is
How to fetch the dropdownlist value and determine its datatye from SQL server

how to implement the scenario
help me with some examples or pseudo code
Please Help



Regards
Priyanka
Posted
Comments
Mahesh Bailwal 3-Sep-13 3:22am    
what you have tried so far?
Priyanka Bhagwat 3-Sep-13 3:28am    
hi,,i have tried stuff from this page.but not able to apply it for my dropdown value
http://stackoverflow.com/questions/9712698/get-data-type-of-a-sql-server-column-using-c-sharp
Nissim Salomon 3-Sep-13 3:26am    
Hi, MSSQL expose a variety set of views called INFOMATION_SCHEMA you can used the INFOMATION_SCHEMA.COLUMNS in order to retrieve the column data

1 solution

Try:
SQL
SELECT column_name, data_type, is_nullable, character_maximum_length FROM information_schema.COLUMNS WHERE table_name='myTable'
 
Share this answer
 
Comments
Raja Sekhar S 3-Sep-13 3:31am    
+5!
Priyanka Bhagwat 3-Sep-13 3:35am    
hithanks
but i want the datatype of particular column
how to find that??
idenizeni 3-Sep-13 3:41am    
Just add to the WHERE clause a condition for the column you want...

SELECT column_name, data_type, is_nullable, character_maximum_length FROM information_schema.COLUMNS WHERE table_name='myTable' AND column_name='myColumnName'
Raja Sekhar S 3-Sep-13 3:41am    
u can use where Column_name='columnName' and Table_name='TableName'
OriginalGriff 3-Sep-13 3:41am    
You can either use the above to find the column name and match it against the drop down selected value, or you could add a WHERE clause to the query to return only the column you are interested in. Depends on how your mind works, and how you prefer to code. Either way don't forget to check the the case where the column is not found!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900