gpt4 book ai didi

c# - 错误 :Cannot implicitly convert type 'System.DateTime' to 'System.Data.Common.DbParameter'

转载 作者:行者123 更新时间:2023-11-30 22:38:26 34 4
gpt4 key购买 nike

我在后面的代码中遇到错误,我不确定下一步该怎么做

前端(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 />

而后端的代码是

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);

    }

粗体代码是抛出错误的行。

我该如何解决这个问题,任何输入都会很好。

谢谢

最佳答案

你设置错了,应该是:

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

请注意您的代码中缺少的 .Value。您正在尝试将 DateTime 分配给 DbParameter

关于c# - 错误 :Cannot implicitly convert type 'System.DateTime' to 'System.Data.Common.DbParameter' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6129177/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com