错误:无法将类型\'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();
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...