Joseph

Joseph

  • NA
  • 11
  • 0

Select multiple items from DataTable based on multiple criteria...

Oct 30 2009 4:51 PM
Hello, I have a bit of an interesting scenario that I need assistance with. I have a DataTable that has five columns. The last column is the date that the record was created. The first column is for the product name. I need to be able to pull the oldest date per product. Is this possible without Linq? I know that I can sort the DataTable and get the oldest overall. And, I could also just set up DataTables per product and pull the information from there. Is there a way to accomplish this with one DataTable? Snippet below:
            dt.Columns.Add("CaseNumber");
dt.Columns.Add("Subject");
dt.Columns.Add("Description");
dt.Columns.Add("Owner");
dt.Columns.Add("CreatedDate");

for (int i = 0; i < qr.records.Length; i++)
{
Case newCase = (Case)qr.records[i];
DataRow dr = dt.NewRow();
dr["CaseNumber"] = newCase.CaseNumber;
dr["Subject"] = newCase.Subject;
dr["Description"] = newCase.Description;
dr["Owner"] = newCase.Owner.Name1;
dr["CreatedDate"] = newCase.CreatedDate;
dt.Rows.Add(dr);

So, what I need is to find all records by a particular product in the "Owner" column and then select the oldest case by the "CreatedDate" column.

Answers (10)