none
How to Search the Data using the DatePicker Value

    Question

  • Hi,

    I am using VS2003 , in my application i used the Two DatePicker Control.on is From date and another is TO date. Using that DatePicker Control i am storing the data in to the Database. But iam not able to search the data using Datepicker Value. First i select the both the value and press the search button then other textbox seraching is working but the date is not working.

    I enclosed the code which i used to search the data using the Text box

    If txtImageNo.Text.Trim <> "" Then StrSQL.Append("AND ImageNo = '" & txtImageNo.Text.Trim & "'")

    Please tel me how to solve this problem

    Thanks in Advance.

    A.Farooque Ali.


    farooque
    • Moved by CaddreModerator Saturday, August 09, 2008 11:42 AM wrong forum (Moved from 64-Bit .NET Framework Development. to .NET Base Class Library)
    Saturday, August 09, 2008 7:26 AM

All replies

  • I'm a little confused, what exactly is not working? Could you please provide the rest of the code, where you set up the search criteria based on the datepicker value? Also you may need to put an extra space before the AND keyword in the StrSQL.Append call (but then maybe you don't, I'm not sure).
    Saturday, August 09, 2008 2:48 PM
  • Hi,

    Thanks for your Reply,

    I am using two datepicker value fromdate and todate, using that datepicker value i am storing the datas in to the database. After the inserting the data , i wrote the coding for searching the data.  There is three types of searching one providerwise and another is dropdownlist finally datewise.

    At first i passed these values,

    Dim StrSQL As New System.Text.StringBuilder

    StrSQL.Append("SELECT DISTINCT ImageNo,Account_Names,Batch_Type,fldvImageIndex,BatchDate_from,BatchDate_To FROM Importimage")

    StrSQL.Append(" WHERE 1=1")

    If txtImageNo.Text.Trim <> "" Then StrSQL.Append("AND ImageNo = '" & txtImageNo.Text.Trim & "'")

    the provider name wise search is working but other two are not working and also i dont know how to write code to search those values.
    Please tell me how to solve this problem.


    Thanks
    Farooque ALi.A


    farooque
    Monday, August 11, 2008 1:41 PM
  • To use combobox / datetimepicker instead of a textbox, just replace the txtImageNo.Text with myCombo.SelectedText or myDateTimePicker.Value.ToString. Use appropriate columns. For the date, you may need to change the SQL code to something like

    " AND date >= '" + FromDate.Value.ToString + "' AND date <= '" + ToDate.Value.ToString + "'"

    Also I still don't think that your SQL statement will work if you don't put a space here:

    StrSQL.Append(" (extra space here) AND ImageNo = ....

    (But then maybe I'm wrong.)

    If you want to use all the filters at the same time, just append all the filtering conditions to your SQL string, you probably know that. Also inserting parameters the way you're doing it is not the best idea, try using SqlCommand.Parameters to do it better.

    I'm not sure if I answered your question, if not feel free to explain it again :).
    • Marked as answer by Zhi-Xin Ye Wednesday, August 13, 2008 10:44 AM
    • Unmarked as answer by Farooque Ali Tuesday, August 19, 2008 6:01 AM
    Tuesday, August 12, 2008 10:04 PM