3
Answers

Cannot implicitly convert System.Collections.Generic.List to

Photo of mike idowu

mike idowu

7y
148
1
I have this code as shown in the diagram below:
 
 
and I have this error 
 
Cannot implicitly convert type 'System.Collections.Generic.List' to 'BPP.CCSP.Admin.Web.ViewModels.AdminVM.CountriesViewModel' 
 
Please how do I resolve it. 

Attachment: listcountry.zip

Answers (3)

3
Photo of Nitin Sontakke
NA 11.7k 2.2k 8y
Can you not have both == and > that way, if app runs after the expected date the greater than will catch that condition. Simple!
 
Accepted
3
Photo of Amit Gupta
NA 16.5k 25.7k 8y
@Abhilash
Yes, you got the point, below snippet will help you to get totaldays
  1. var totalDays = (startDate.Date - endDate.Date).TotalDays;  
 
2
Photo of Nigel Fernandes
NA 4k 139k 8y
Scheduled task is the best approach for this.
1
Photo of Nitin Sontakke
NA 11.7k 2.2k 8y
In my personal opinion, it is best to have a scheduled task. The reason for that is, it is not guaranteed that your application will run everyday.
 
For activities such as these it is best to have a separate app. As you will proceed, may be you will find more such things and you can club them all together.
 
 
1
Photo of Amit Gupta
NA 16.5k 25.7k 8y
Instead of complicating the things like scheduling the task, you may delete the rows at the time of form load on a seperate thread that read your data and days and perform the operation.
0
Photo of Mani Kandan
NA 2.6k 135.8k 8y
Hello Amit,
 
Sir ,I have write the code like this. Now all are working fine. But I have doubt, by using this code, 
  1.   if (DateTime.Now.Date == calculatedDate.Date)  
  2.             {  
  3. /*here, then written the code for delete records*/  
  4. }  
Here, the calculatedDate is the after adding number of day then I get date with respect to no of days using c# adddays code. (eg: if i am giving 10 days from current date then calculatedDate will 23/01/2017)
 
The problem is if the application not run at calculatedDate
 then how can I mange this condition?  if (DateTime.Now.Date == calculatedDate.Date)
 
Please help me. 
0
Photo of Mani Kandan
NA 2.6k 135.8k 8y
Hello Bikesh,
 
Yes, I am just planing like this
 
"Then, I think that, have to get date with respect to the given number of days and then save that date to the database. Again, check the date on listview binding page load like if the date equal to the current date. If the apps will not run every day, that is also the data is over, to solve this issue have to write c# code like if the given date is over when the apps run on next day should have to delete records. Is this right way? I don't know how to create scheduler for up windows application also for this situation."
 
But, also I am thinking about how to do scheduler while installing my apps on any other customer local mechine... 
0
Photo of Nitin Sontakke
NA 11.7k 2.2k 8y
Abhilash, this is all very simple, if you google you will get everything. Seriously.
 
First, is it okay for you if the deletion happens after few days? Then you write the code in current app. If this is not acceptable write another windows console app and write code there.
 
The number entered by use should be stored by you anyway.  
 
Scheduling an exe is very very simple, just google and you will get steps.
 
Exe will run every day, when to delete and what to delete is your C# and db logic.
 
Write a sp which will do all the addition of date and days and return the files to be deleted.
 
0
Photo of Mani Kandan
NA 2.6k 135.8k 8y
Hello Nitin Sir,
 
Then, I think that, have to get date with respect to the given number of days and then save that date to the database. Again, check the date on listview binding page load like if the date equal to the current date. If the apps will not run every day, that is also the data is over, to solve this issue have to write c# code like if the given date is over when the apps run on next day should have to delete records. Is this right way? I don't know how to create scheduler for up windows application also for this situation.
 
Thanks
Abhilash.J.A 
0
Photo of Mani Kandan
NA 2.6k 135.8k 8y
Hello Amit,
 
Sir, with respect to your advice after add days and save the number days on table and every page load time check the currendays if equal to saved days if it is true then delete  records from table or if not show details inside listveiw. Is it currect ? 
 
Thanks,
Abhilash.J.A 
-1
Photo of Bikesh Srivastava
NA 19.8k 835.2k 8y
have you tried something ,i think no need to use task scheudlar