I am using Visual Studio 2010 and SQL Management Studio R2. Although the sql query works fine in sql management studio. This makes an exception in visual studio. From the exclusion of the index, which I am editing to make any other adjustments that it throws out of the format exception. Please, help. The code is as follows:
string sql = "SELECT DISTINCT Year(tdate) FROM saletransaction ORDER BY Year(tdate) DESC"; cmd = new SqlCommand(sql, con); dr = cmd.ExecuteReader(); DateTime dt; while (dr.Read()) { if (dr.HasRows == true) { dt = Convert.ToDateTime(dr["tdate"].ToString());
source share