Error :Cannot implicitly convert type 'System.DateTime' to 'System.Data.Common.DbParameter'
我在代码中发现了错误,我不确定下一步该怎么做
前端(ASP.NET)中的代码是
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <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] >= @Txt_selected_start_date) AND ([Pay Period End date] <= @Txt_selected_end_date) AND (LoginName = '[email protected]')" OnSelecting="SqlDataSource2_Selecting" > <SelectParameters> <asp:parameter Name="Txt_selected_start_date" Type="DateTime" /> </SelectParameters> </asp:SqlDataSource> <br /><br /> Start Date: </asp:TextBox> End Date: </asp:TextBox> <br /> <br /><br /> |
当后端的代码是
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);
1 }
号
粗体代码是引发错误的行。
如何解决这个问题,任何输入都会很好。
谢谢
你错了,应该是:
注意代码中缺少的.value。您试图将一个
尝试
1 | e.Command.Parameters["@Txt_selected_start_date"].Value = DateTime.Parse(TxtDatepicker_start.Text) |
或
1 | e.Command.Parameters["@Txt_selected_start_date"].Value = DateTime.Parse(TxtDatepicker_start.Text).ToShortDateString(); |
号