none
Date Range Rowfilter from datetime picker to dataview RRS feed

  • Question

  • I have created a datagrid view i want to filter its data according to date ranges between 2 DateTimePicker I am not able to create a row filter for the dataview which i am assigning to the datagrid as source.

    My database formate of that column is

    TO_CHAR(a.ord_order_time, 'DD-MM-YY HH:MI') as "Order_Time",
     and in coding

     filter = string.Format("Order_Time >= {0:dd-MM-yy HH:MM } AND Order_Time < {1:dd-MM-yy HH:MM }", dtpFrom.Value, dtpTo.Value);

    using above code for the filter it will give me exceptions .

    Plz provide me appropriate code snippets to create rowfilter regarding dateRange


    SaiVaibhav@Acumen

    Thursday, May 17, 2012 12:32 PM

Answers

  • THanks Mike for u r suggestions i have done an alternative solution for that problem.

    I have added one more column to the dataset which is dateTime.OADate() it converts my date to OLE automation format which i have used for the comparision of the date.

    Thanks


    SaiVaibhav@Acumen

    Monday, May 21, 2012 4:14 AM

All replies

  • Hi Vaibhav,

    Welcome to the MSDN Forum.

    Since you have convert the datetime value to a string in your sql statement. So you need to convert the datetime picker value to strings, too.

    And please try the following code:

    filter = string.Format("Order_Time >= '{0:dd-MM-yy HH:MM }' AND Order_Time < '{1:dd-MM-yy HH:MM }'", dtpFrom.Value, dtpTo.Value);

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, May 18, 2012 11:07 AM
    Moderator
  • Thanks Mike for ur suggestion but its not working.

    Plz provide any other way of doing this.


    SaiVaibhav@Acumen

    Friday, May 18, 2012 12:18 PM
  • Hi Vaibhav,

    To give a effective answer, would you like to tell me more about your issue?

    How do you hold the data from the database in your program? Do you keep it in a datatable or dataset?

    If so, What is the type of the Order_Time column in your datatable? Is it a string or a datetime type, or something else? And this way can get the column data type: http://msdn.microsoft.com/en-us/library/system.data.datacolumn.datatype.aspx

    I look forward you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 21, 2012 3:48 AM
    Moderator
  • Thanks Mike for ur suggestion but its not working.

    Plz provide any other way of doing this.


    SaiVaibhav@Acumen

    Hi Vaibhav,

    And more, you have said it doesn't work, does it mean you still get exceptions? So please tell the exceptions.

    Or you don't get any exceptions, just don't get the expected result.

    I look forward you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 21, 2012 3:54 AM
    Moderator
  • THanks Mike for u r suggestions i have done an alternative solution for that problem.

    I have added one more column to the dataset which is dateTime.OADate() it converts my date to OLE automation format which i have used for the comparision of the date.

    Thanks


    SaiVaibhav@Acumen

    Monday, May 21, 2012 4:14 AM
  • This is fully valid syntax and is working fully with using datatimepicker form control..
    Monday, February 18, 2019 6:10 PM
  • Hi Vaibhav,

    Welcome to the MSDN Forum.

    Since you have convert the datetime value to a string in your sql statement. So you need to convert the datetime picker value to strings, too.

    And please try the following code:

    filter = string.Format("Order_Time >= '{0:dd-MM-yy HH:MM }' AND Order_Time < '{1:dd-MM-yy HH:MM }'", dtpFrom.Value, dtpTo.Value);

    I hope this will be helpful.

    Best regards,



    a small fix:

    filter = string.Format("Order_Time >= '{0:dd-MM-yyyy}' AND Order_Time < '{1:dd-MM-yyyy}'", dtpFrom.Value, dtpTo.Value);

    Monday, February 18, 2019 6:18 PM