作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在后面的代码中遇到错误,我不确定下一步该怎么做
前端(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] >= @Txt_selected_start_date) AND ([Pay Period End date] <= @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>
End Date: <asp:TextBox ID="TxtDatepicker_end" runat="server" Width = 125px >
</asp:TextBox>
<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/
我是一名优秀的程序员,十分优秀!