错误:无法将类型\'System.DateTime\'隐式转换为\'System.Data.Common.DbParameter\'

| 我的代码后面出现错误,我不确定下一步该怎么做 前端(asp.net)中的代码是
<asp:SqlDataSource ID=\"SqlDataSource2\" runat=\"server\" 
                ConnectionString=\"<%$ ConnectionStrings:LicensingConnectionString %>\" 



                SelectCommand=\"SELECT [School Name], [School City], [School State], LoginName, [Current Sales], Commission, [Pay Period start date], [Pay Period End date] FROM commissions WHERE ([Pay Period start date] &gt;= @Txt_selected_start_date) AND ([Pay Period End date] &lt;= @Txt_selected_end_date) AND (LoginName = \'mervinj@uw.edu\') \" 
                OnSelecting=\"SqlDataSource2_Selecting\"
                >
                <SelectParameters>
                    <asp:parameter  
                        Name=\"Txt_selected_start_date\" Type=\"DateTime\" />
                    <asp:Parameter Name=\"Txt_selected_end_date\"  Type=\"DateTime\" />
                </SelectParameters>
            </asp:SqlDataSource>



<asp:PlaceHolder ID=\"pnlwithdates\" runat=\"server\" Visible=\"false\"> 
<div style=\"padding: 0 200px 0 200px\">
<br /><br />
Start Date: <asp:TextBox ID=\"TxtDatepicker_start\" runat=\"server\" Width = 125px >
      </asp:TextBox>

      &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 />
<br /><br />
而后端的代码是   受保护的空白   SqlDataSource2_Selecting(对象   发件人,   SqlDataSourceSelectingEventArgs e)           {               e.Command.Parameters [\“ @ username \”]。Value   = HttpContext.Current.User.Identity.Name;               e.Command.Parameters [\“ @ Txt_selected_start_date \”]   = DateTime.Parse(TxtDatepicker_start.Text);
    }
粗体代码是引发错误的行。 我该如何解决这个问题,任何输入都会很棒。 谢谢     
已邀请:
您设置错了,应该是:
e.Command.Parameters[\"@Txt_selected_start_date\"].Value = DateTime.Parse(TxtDatepicker_start.Text);
请注意您的代码中缺少的.Value。您正在尝试将
DateTime
分配给
DbParameter
。     
尝试
e.Command.Parameters[\"@Txt_selected_start_date\"].Value = DateTime.Parse(TxtDatepicker_start.Text)
要么
e.Command.Parameters[\"@Txt_selected_start_date\"].Value = DateTime.Parse(TxtDatepicker_start.Text).ToShortDateString();
    

要回复问题请先登录注册