简体   繁体   中英

datatable select filter where column timespan

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 在此处输入图片说明 .

EDITED : timeOnlyStart is a column start

在此处输入图片说明

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() 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM