Click here to Skip to main content
15,914,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
this is my code
C#
using (DBNezamEntities DBNezamEntitie = new DBNezamEntities()) {
         PersianCalendar persiancalandar = new PersianCalendar();
         var Query = from Newes in DBNezamEntitie.News
                      select new
                      {
                          Newes.Title,
                          Newes.Summary,
                          HasbinUpdate = (persiancalandar.GetYear(Newes.UpdateDateTime).ToString() + "/" + persiancalandar.GetMonth(Newes.UpdateDateTime).ToString() + "/" + persiancalandar.GetDayOfMonth(Newes.UpdateDateTime).ToString() + " " + persiancalandar.GetHour(Newes.UpdateDateTime).ToString() + ":" + persiancalandar.GetMinute(Newes.UpdateDateTime).ToString() + ":" + persiancalandar.GetSecond(Newes.UpdateDateTime).ToString() + "" + persiancalandar.GetEra(Newes.UpdateDateTime).ToString()).ToString(),
                          Groupes = Newes.Genre.Name
                      };

         GridView1.DataSource = Query;
         GridView1.DataBind();

     }


and give me this error:
Error pic please click
Posted
Updated 4-Oct-13 0:18am
v3
Comments
Azee 4-Oct-13 4:44am    
Please verify your link.
Thanks7872 4-Oct-13 5:00am    
Why link to error? And even that one is not working. Why don't you explain here what the error is?

1 solution

Hi,
check this.
C#
using (DBNezamEntities DBNezamEntitie = new DBNezamEntities()) {
            PersianCalendar persiancalandar = new PersianCalendar();
            var Query = from Newes in DBNezamEntitie.News.AsEnumerable() // add AsEnumerable()
                         select new
                         {
                             Newes.Title,
                             Newes.Summary,
                             HasbinUpdate = (persiancalandar.GetYear(Newes.UpdateDateTime).ToString() + "/" + persiancalandar.GetMonth(Newes.UpdateDateTime).ToString() + "/" + persiancalandar.GetDayOfMonth(Newes.UpdateDateTime).ToString() + " " + persiancalandar.GetHour(Newes.UpdateDateTime).ToString() + ":" + persiancalandar.GetMinute(Newes.UpdateDateTime).ToString() + ":" + persiancalandar.GetSecond(Newes.UpdateDateTime).ToString() + "" + persiancalandar.GetEra(Newes.UpdateDateTime).ToString()).ToString(),
                             Groupes = Newes.Genre.Name
                         };

            GridView1.DataSource = Query;
            GridView1.DataBind();

        }

hope it helps.
Thanks.
 
Share this answer
 
Comments
Thanks7872 4-Oct-13 4:59am    
How can you assume everything? Do you know what the error is?
Harshil_Raval 4-Oct-13 5:07am    
see this link is posted as error <img src="http://i39.tinypic.com/b97jol.png" border="0" alt="">.
I have check "http://i39.tinypic.com/b97jol.png" this url. in this there is an image.
From that error message i assume this. and the error is ToString() type of casting is not valid in linq query.

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