(I am using LINQ to SQL for retrieving the table from database)
I need to loop through a Database table(the has a field Data) to mach the current date with the date in table.How can i achieve this?
(I am using LINQ to SQL for retrieving the table from database)
I need to loop through a Database table(the has a field Data) to mach the current date with the date in table.How can i achieve this?
Don't use a loop - this will be extremely slow if the table is large. You want to do this in a set based fashion - the IQueryable .Where() method, i.e:
MyTable.Where(x => x.SomeDate == DateTime.Today);
This assumes the dates in the DB store the date part only. If the time part is stored in the DB and you want to ignore that in the comparison, you need to do something like:
MyTable.Where(x => x.SomeDate >= DateTime.Today && x.SomeDate < DateTime.Today.AddDays(1));