c# datatable select statement with dates

后端 未结 5 1372
难免孤独
难免孤独 2021-01-12 06:16

i am trying to make a select statement on a datatable to get the row that is within the date range i am looking for. I am new to this an i dont quite understand how this sel

5条回答
  •  情深已故
    2021-01-12 06:22

    Using this inside an SSIS script component. I just used the example from above that included "#" around the dates. Also I converted each to string. This worked perfectly.

    Just in case you want to know how I setup this up inside SSIS: First had a data flow using the recordset destination with an Object variable to store the recordset.

    in my script I included the variable as a read only.

    In the main class...

    public class ScriptMain : UserComponent
    {
    
    OleDbDataAdapter a = new OleDbDataAdapter();
    System.Data.DataTable AwardedVacTable = new System.Data.DataTable();
    ...
    ...
    

    then in Pre-Execute...

    public override void PreExecute()
    {
        base.PreExecute();
    
        a.Fill(AwardedVacTable, Variables.rsAwardedVac);
    ...
    ...
    

    then in a custom method accessed the datatable ...

    String dtFilter = "EmployeeID = " + empId.ToString() + " AND (#" + Convert.ToString(StartDate) "# <= EndDate AND #" + Convert.ToString(StartDate) + "# >= StartDate" + " OR #" + Convert.ToString(StartDate.AddDays((double)numDays)) + "# >= StartDate AND #" + Convert.ToString(StartDate.AddDays((double)numDays)) + "# <= EndDate)";
    
    DataRow[] Overlaps = AwardedVacTable.Select(dtFilter);
    

提交回复
热议问题