0

I am pulling a date using the Jquery date picker and storing it in a textbox using the following code

In the head section

<script src="Scripts/jquery.ui.datepicker.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $("#<%= TxtDatepicker_start.ClientID %>").datepicker();
    });
    </script>
<script type="text/javascript">
    $(function () {
        $("#<%= TxtDatepicker_end.ClientID %>").datepicker();
    });
    </script>

In the body section



Start Date:

  &nbsp;&nbsp;End Date: <asp:TextBox ID="TxtDatepicker_end" runat="server" Width = 125px >
  </asp:TextBox>
  &nbsp;&nbsp;&nbsp;&nbsp;<asp:Button ID="Button_daterecords" runat="server"  Text="Show records"  OnClick ="SQLDisplay_Date_records" /><br />



Now the questions is how do I get the value in the text box and convert it to a date (YYYY-MM-DD) format in the code behind ?

I tried typecasting it but then I get this error in the code behind

cannot implicitly convert system.datetime to system.common.dbparameter

The code I am using in the code behind is

protected void SqlDataSource2_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            e.Command.Parameters["@username"].Value = HttpContext.Current.User.Identity.Name;
            e.Command.Parameters["@Txt_selected_start_date"] = DateTime.Parse(TxtDatepicker_start.Text);


        }

Thanks

0

3 Answers 3

1

The problem is that your e.Command.Parameter["..."] is expecting a type other than DateTime. String usually works so try

DateTime.Parse(txtDatepicker_end.Text).ToString("YYYY-MM-dd");

the ToString() method for DateTime will allow you to apply any format you wish to your date.

You also forgot:

e.Command.Parameter["..."]

should be

e.Command.Parameter["..."].Value
0
DateTime.Parse(TxtDatepicker_end.Text);
1
  • Thanks Ken ,but I am getting this error "cannot implicitly convert system.datetime to system.common.dbparameter" when ever I try mapping it to an input variable for a sql query
    – Mervin
    May 25, 2011 at 17:58
0

You need to assign the result to the .Value property of the DbParameter:

e.Command.Parameters["@Txt_selected_start_date"].Value = DateTime.Parse(TxtDatepicker_start.Text);

Not the answer you're looking for? Browse other questions tagged or ask your own question.