0

i want to ask, how do i set condition or expression where the column table is type of timespan. when i use this code

private void button1_Click(object sender, EventArgs e)
    {
        string expression2;
        expression2 = "timeOnlyStart < '" + TimeSpan.Parse("10:00:00") + "'";
        DataTable yyy = dt_Main.Select(expression2).CopyToDataTable();
        gridControl3.DataSource = yyy;
    }

it gives me error enter image description here.

EDITED : timeOnlyStart is a column start

enter image description here

3
  • Probably you define the timeOnlyStart as varchar or nvarchar, because of that you receive this error. Nov 23, 2016 at 4:44
  • What is the data type timeOnlyStart ?
    – Mahesh
    Nov 23, 2016 at 4:45
  • iam not sure, from what i see is time span. i dont have any access of the sql server. the thing is the person in charge take a break for 1 day. Nov 23, 2016 at 4:50

1 Answer 1

2

You can use Linq to filter rows

var results = from myRow in dt_Main.AsEnumerable()
              where myRow.Field<TimeSpan>("timeOnlyStart") < TimeSpan.Parse("10:00:00")
              select myRow;
gridControl3.DataSource  = results.AsDataView();

if you need datatable

 var resultsdt = results.CopyToDataTable() 
3
  • thx it works. is there another way than using linq. never use linq before.. just curios :) Nov 23, 2016 at 6:05
  • is there a way to store it in datatable ?, i need to parse the datatable to other form Nov 23, 2016 at 6:06
  • @chopperfield Select expressions can be used but with TimeSpan it is difficult to compare. check my update for convert result back to DataTable
    – Damith
    Nov 23, 2016 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.