How to modify DataTable rows using Select() or LINQ

Posted on 2011-04-19
Last Modified: 2013-12-16

I've a DataTable with some tasks an starttime and endtime like this:
Action            StartTime      EndTime
Sleep            9:04            9:54
Breakfast              9:54            10:31
Go to work      10:31      11:07

Now I need to modify the rows if I need entries to insert, e.g. shower from 9:41 to 10:08 :

Action            StartTime      EndTime
Sleep            9:04            9:41
Shower           9:41         10:08
Breakfast              10:08      10:31
Go to work      10:31      11:07

Till now I had a MDB as backend so I get the rows by a SQL command like:
SELECT * FROM table WHERE (StartTime BETWEEN NewStartTime AND NewEndTime) OR (EndTime BETWEEN NewStartTime AND NewEndTime)

With the rows returned by the query I do a lot of string operations to compare what I've to change / update / insert and store these results back to my MDB.

The matter is that I've no more a backend so I've to do these operations in memory now...

So would to you think is a way to do so, I tried mydt.Select("(StartTime BETWEEN NewStartTime AND NewEndTime) OR (EndTime BETWEEN NewStartTime AND NewEndTime)") reports an error for BETWEEN so I think I can't use it - or do I something wrong?

Oris there a simple way you use with LinQ?
As I'm a novice with LinQ I may need some useful hints for how to do something like tis ...


Question by:andre72
    LVL 83

    Accepted Solution


    mydt.Select("(StartTime >= NewStartTime AND StartTime <= NewEndTime) OR (EndTime >= NewStartTime AND EndTime <= NewEndTime)")
    LVL 12

    Assisted Solution

    by:Mohamed Abowarda

    Author Closing Comment

    Thanks for your support

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    This video discusses moving either the default database or any database to a new volume.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now