I wish to insert a Date value in DataRow[] and find a DateTime value in a column. The Date value entered will be passed to a var to perform another search. But it cannot be passed, can any1 help me fix my code?
//Receive StartDateTime value
DataRow[] setStartDateTime = DataSet1
.Tables["table1"]
.Select("StartDateTime =#" + searchMonth + "/" + searchDay + "/" + searchYear + "#");
//Count PcrID rows which same row with StartDateTime
var PcrID_1 = DataSet1
.Tables["table1"]
.AsEnumerable()
.Where(c => c.Field<DateTime>("StartDateTime") == setStartDateTime) /*Error occurs here: Operator '==' cannot be applied to operands of type 'System.DateTime' and 'System.Data.DataRow[]'*/
.Select(d => d["PcrID"]);
Pcr_1 = PcrID_1.Count();
Once you filtered rows by date-time you need to apply
Selecton that bunch of rows. For example,Of course , above code doesn’t make sense if all you want is the count then you can very well do that by saying
Or you can do the original filtering using LINQ – for example,
The first and last example code actual produces enumeration of PcrID for the given date.
If you want a distinct list then you can use Distinct extension method – for example