Skip to content
Advertisement

How to select distinct year from a datetime column and add the result to a comboBox in C#?

I am using visual studio 2010 and SQL Management Studio R2 Although the sql query works fine in sql management studio. Its throws an exception in visual studio. Out of index exception whem i edit to make any other adjustments it throws Out of format exception. Please Help me. The code is as follows:

Advertisement

Answer

You’re not selecting tdate but you select Year(tdate)

I would modify the query to this:

and access it with dr["tdate_year"]

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement