错误:无法隐式转换类型“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] >= @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" />
<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 />
而后端的代码是
受保护的无效 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);
<前><代码>}
粗体代码是引发错误的行。
我该如何解决这个问题,任何输入都会很棒。
谢谢
I am getting the error in my code behind and I am not sure what to do next
The code in the front end (asp.net) is
<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" />
<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 />
while the code at the backend 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);}
The bolded code is the line which is throwing the error .
How do I fix this,any inputs would be great.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您设置错误,应该是:
e.Command.Parameters["@Txt_selected_start_date"].Value = DateTime.Parse(TxtDatepicker_start.Text);
请注意您的 .Value代码。您正在尝试将
DateTime
分配给DbParameter
。You're setting it wrong, it should be:
e.Command.Parameters["@Txt_selected_start_date"].Value = DateTime.Parse(TxtDatepicker_start.Text);
Note the .Value that is missing in your code. You're trying to assign a
DateTime
to aDbParameter
.尝试
或
Try
Or