data between two dates in asp.net2008

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tracy6001
    New Member
    • Nov 2009
    • 4

    data between two dates in asp.net2008

    hi,
    i am trying to fetch three fields from my table according to the two dates which will be given by the user in two text boxes in my form..
    i am facing a problem..
    my dates in the database is in the text format..
    it is in the form of
    10/10/2009
    11/10/2009
    12/10/2009
    12/12/2009
    now if i give two dates like 10/10/2009 in textbox1 and 12/10/2009 in textbox2 my datagrid shows allthe data including 12/12/2009...means it is not filtering the month...
    my asp.net coding is like this
    SELECT [Name], [Date], [TotalHrs] FROM [fabotentry] WHERE (([Date] >= ?) AND ([Date] < ?))

    my vb.net coding is like this
    select Name,Date,Total Hrs from fabotentry where Date between '" & tb1.Text & "' and '" & tb2.Text & "'"

    what should i do now???
    thanks
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    The best way to do this is to parse the entry in the TextBox into a DateTime object, then instead of using string concatenation to build raw SQL, use Parameters.

    This will also help protect you from SQL Injection attacks.

    Comment

    Working...