0
public List<Data> GetData(string Date1, string Date2, string param3)
{
    var myData= new List<FindData_Result>();
    using (var context = new Config())
    {
        var queryResult = context.FindData(startDate, endDate, param3);
        final= (from a in queryResult select a).ToList();
    }
}

How do I pass date1 and end date2 as datetime parameter to my stored procedure?

I am using MVC web api with entity framework (DB first approach)

Christos
  • 53,228
  • 8
  • 76
  • 108
HDev007
  • 325
  • 2
  • 6
  • 15
  • if your values are valid for `DateTime`, then just make the parameters `DateTime Date1, DateTime Date2` (but I assume you mean `startDate` and `endDate`, not `Date1` and `Date2`) –  Mar 05 '17 at 11:55

1 Answers1

1

You should convert the string representations of your dates, start date and end date, to their DateTime equivalent. This can be done by using the Parse method of DateTime type, like below:

var startDate = DateTime.Parse(Date1);
var endDate = DateTime.Parse(Date2);
var queryResult = context.FindData(startDate, endDate, param3).ToList();

You could also use the ParseExact method, provided that your string have a specific format. For further info please have a look here.

Christos
  • 53,228
  • 8
  • 76
  • 108
  • tried this and getting message "The result of a query cannot be enumerated more than once" – HDev007 Mar 05 '17 at 11:12
  • var queryResult = context.FindData(startDate, endDate, param3); in this line – HDev007 Mar 05 '17 at 11:13
  • @HDev007 call `ToList` at the end and it will be fixed. Doing so you don't need any more the variable called `final`. – Christos Mar 05 '17 at 11:14
  • 1
    I read about the error message you mentined and I found this helpful link http://stackoverflow.com/questions/5723555/the-result-of-a-query-cannot-be-enumerated-more-than-once. Pay attention on the last comment made by Ageis, below the accepted answer. – Christos Mar 05 '17 at 11:20
  • Thanks Christos for help :-) – HDev007 Mar 05 '17 at 11:23