2016-05-31 61 views
0

我有一个数据库,存储来自用户的彩票表单提交。其中一列是每当有人提交表单时用当前日期时间填充的DateTime列。我希望能够通过DateTime列进行搜索,这样我就可以提取在特定日期输入的所有表单。DateTime搜索问题ASP.NET

我在执行搜索时没有收到任何错误,只是我的自定义消息“没有符合该搜索条件的结果”。我试过禁用jquery datepicker,并尝试从数据库复制并粘贴确切的DateTime字段到搜索框中,仍然没有。显然我错过了一些东西,但我无法弄清楚什么。任何帮助深表感谢。

C#代码:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data.SqlClient; 
using System.Configuration; 

public partial class adminDefault : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

} 

protected void lastNameButton(object sender, EventArgs e) 
{ 

    SqlConnection conn; 
    SqlCommand comm; 
    string connectionString = ConfigurationManager.ConnectionStrings["10thLottoApp"].ConnectionString; 
    conn = new SqlConnection(connectionString); 
    comm = new SqlCommand("SELECT First, Last, Addr1, C, S, Z, dayphone, eveningphone, email, tripCC, tripCCexpiration, tripCVV, tripCCname, memberCC, memberCCexpiration, memberCVV, memberCCname, membership, hutCredit, creditName, GroupName, Id, LotteryChoices, dateTime FROM Lotto WHERE Last LIKE '%'+ @Name + '%'", conn); 
    comm.Parameters.Add("@Name", System.Data.SqlDbType.NVarChar, 50).Value = nameSearch.Text; 

     conn.Open(); 
     SqlDataReader reader = comm.ExecuteReader(); 
     if (!reader.HasRows) 
      { 
       noMatchLabel.Text = "No results matching that search criteria."; 
      } 
     else 
     { 
      grid.DataSource = reader; 
      grid.DataKeyNames = new string[] { "Id" }; 
      grid.DataBind(); 
      reader.Close(); 
      conn.Close(); 
      noMatchLabel.Text = null; 
     } 

} 


protected void groupNameButton(object sender, EventArgs e) 
{ 
    SqlConnection conn; 
    SqlCommand comm; 
    string connectionString = ConfigurationManager.ConnectionStrings["10thLottoApp"].ConnectionString; 
    conn = new SqlConnection(connectionString); 
    comm = new SqlCommand("SELECT First, Last, Addr1, C, S, Z, dayphone, eveningphone, email, tripCC, tripCCexpiration, tripCVV, tripCCname, memberCC, memberCCexpiration, memberCVV, memberCCname, membership, hutCredit, creditName, GroupName, Id, LotteryChoices, dateTime FROM Lotto WHERE GroupName LIKE '%'+ @GroupName + '%'", conn); 
    comm.Parameters.Add("@GroupName", System.Data.SqlDbType.NVarChar, 50).Value = groupSearch.Text; 

    conn.Open(); 
    SqlDataReader reader = comm.ExecuteReader(); 
    if (!reader.HasRows) 
    { 
     noMatchLabel.Text = "No results matching that search criteria."; 
    } 
    else 
    { 
     grid.DataSource = reader; 
     grid.DataKeyNames = new string[] { "Id" }; 
     grid.DataBind(); 
     reader.Close(); 
     conn.Close(); 
     noMatchLabel.Text = null; 
    } 
} 

protected void dateSearch(object sender, EventArgs e) 
{ 
    SqlConnection conn; 
    SqlCommand comm; 
    string connectionString = ConfigurationManager.ConnectionStrings["10thLottoApp"].ConnectionString; 
    conn = new SqlConnection(connectionString); 
    comm = new SqlCommand("SELECT First, Last, Addr1, C, S, Z, dayphone, eveningphone, email, tripCC, tripCCexpiration, tripCVV, tripCCname, memberCC, memberCCexpiration, memberCVV, memberCCname, membership, hutCredit, creditName, GroupName, Id, LotteryChoices, dateTime FROM Lotto WHERE dateTime = @dateTime ", conn); 

    comm.Parameters.Add("@dateTime", System.Data.SqlDbType.DateTime).Value = DateTime.Parse(datesearch.Text); 

    conn.Open(); 
    SqlDataReader reader = comm.ExecuteReader(); 
    if (!reader.HasRows) 
    { 
     noMatchLabel.Text = "No results matching that search criteria."; 
    } 
    else 
    { 
     grid.DataSource = reader; 
     grid.DataKeyNames = new string[] { "Id" }; 
     grid.DataBind(); 
     reader.Close(); 
     conn.Close(); 
     noMatchLabel.Text = null; 
    } 

} 

protected void grid_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    BindLottoDetails(); 
} 

private void BindLottoDetails() 
{ 
    int selectedRowIndex = grid.SelectedIndex; 
    int lottoId = (int)grid.DataKeys[selectedRowIndex].Value; 
    SqlConnection conn; 
    SqlCommand comm; 
    SqlDataReader reader; 
    string connectionString = ConfigurationManager.ConnectionStrings["10thLottoApp"].ConnectionString; 
    conn = new SqlConnection(connectionString); 
    comm = new SqlCommand("SELECT Id, First, Last, Addr1, C, S, Z, dayphone, eveningphone, email, tripCC, tripCCexpiration, tripCVV, tripCCname, memberCC, memberCCexpiration, memberCVV, memberCCname, membership, hutCredit, creditName, GroupName, LotteryChoices, dateTime FROM Lotto WHERE [email protected]", conn); 
    comm.Parameters.Add("Id", System.Data.SqlDbType.Int); 
    comm.Parameters["Id"].Value = lottoId; 
    try 
    { 
     conn.Open(); 
     reader = comm.ExecuteReader(); 
     lottoFormDetails.DataSource = null; 

     lottoFormDetails.DataSource = reader; 
     lottoFormDetails.DataKeyNames = new string[] { "Id" }; 
     lottoFormDetails.DataBind(); 
     reader.Close(); 
    } 
    finally 
    { 
     conn.Close(); 
    } 
} 
protected void lottoFormDetails_ModeChanging(object sender, DetailsViewModeEventArgs e) 
{ 
    lottoFormDetails.ChangeMode(e.NewMode); 
    BindLottoDetails(); 
} 
protected void lottoFormDetails_ItemUpdating(object sender, DetailsViewUpdateEventArgs e) 
{ 
    int LottoId = (int)lottoFormDetails.DataKey.Value; 
    TextBox newFirstTextBox = (TextBox)lottoFormDetails.FindControl("editFirstTextBox"); 
    TextBox newLastTextBox = (TextBox)lottoFormDetails.FindControl("editLastTextBox"); 
    TextBox newAddr1TextBox = (TextBox)lottoFormDetails.FindControl("editAddr1TextBox"); 
    TextBox newCityTextBox = (TextBox)lottoFormDetails.FindControl("editCityTextBox"); 
    TextBox newStateTextBox = (TextBox)lottoFormDetails.FindControl("editStateTextBox"); 
    TextBox newZipTextBox = (TextBox)lottoFormDetails.FindControl("editZipTextBox"); 
    TextBox newdaytimephoneTextBox = (TextBox)lottoFormDetails.FindControl("editdaytimephoneTextBox"); 
    TextBox neweveningphoneTextBox = (TextBox)lottoFormDetails.FindControl("editeveningphoneTextBox"); 
    TextBox newemailTextBox = (TextBox)lottoFormDetails.FindControl("editemailTextBox"); 
    TextBox newmembershipTextBox = (TextBox)lottoFormDetails.FindControl("editmembershipTextBox"); 
    TextBox newhutCreditTextBox = (TextBox)lottoFormDetails.FindControl("edithutCreditTextBox"); 
    TextBox newcreditNameTextBox = (TextBox)lottoFormDetails.FindControl("editcreditNameTextBox"); 
    TextBox newGroupNameBox = (TextBox)lottoFormDetails.FindControl("editGroupNameTextBox"); 
    TextBox newLotteryChoicesTextBox = (TextBox)lottoFormDetails.FindControl("editLotteryChoicesTextBox"); 
    string newFirst = newFirstTextBox.Text; 
    string newLast = newLastTextBox.Text; 
    string newAddr1 = newAddr1TextBox.Text; 
    string newCity = newCityTextBox.Text; 
    string newState = newStateTextBox.Text; 
    string newZip = newZipTextBox.Text; 
    string newdaytimephone = newdaytimephoneTextBox.Text; 
    string neweveningphone = neweveningphoneTextBox.Text; 
    string newemail = newemailTextBox.Text; 
    string newmembership = newmembershipTextBox.Text; 
    string newhutCredit = newhutCreditTextBox.Text; 
    string newcreditName = newcreditNameTextBox.Text; 
    string newGroupName = newGroupNameBox.Text; 
    string newLotteryChoices = newLotteryChoicesTextBox.Text; 
    SqlConnection conn; 
    SqlCommand comm; 
    string connectionString = ConfigurationManager.ConnectionStrings["10thLottoApp"].ConnectionString; 
    conn = new SqlConnection(connectionString); 
    comm = new SqlCommand("UpdateLotteryForm", conn); 
    comm.CommandType = System.Data.CommandType.StoredProcedure; 
    comm.Parameters.Add("Id", System.Data.SqlDbType.Int); 
    comm.Parameters["Id"].Value = LottoId; 
    comm.Parameters.Add("NewFirst", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["NewFirst"].Value = newFirst; 
    comm.Parameters.Add("NewLast", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["NewLast"].Value = newLast; 
    comm.Parameters.Add("NewAddr1", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["NewAddr1"].Value = newAddr1; 
    comm.Parameters.Add("NewC", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["NewC"].Value = newCity; 
    comm.Parameters.Add("NewS", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["NewS"].Value = newState; 
    comm.Parameters.Add("NewZ", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["NewZ"].Value = newZip; 
    comm.Parameters.Add("Newdayphone", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["Newdayphone"].Value = newdaytimephone; 
    comm.Parameters.Add("Neweveningphone", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["Neweveningphone"].Value = neweveningphone; 
    comm.Parameters.Add("Newemail", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["Newemail"].Value = newemail; 
    comm.Parameters.Add("Newmembership", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["Newmembership"].Value = newmembership; 
    comm.Parameters.Add("NewhutCredit", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["NewhutCredit"].Value = newhutCredit; 
    comm.Parameters.Add("NewcreditName", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["NewcreditName"].Value = newcreditName; 
    comm.Parameters.Add("NewGroupName", System.Data.SqlDbType.NVarChar, 50); 
    comm.Parameters["NewGroupName"].Value = newGroupName; 
    comm.Parameters.Add("NewLotteryChoices", System.Data.SqlDbType.NVarChar, -1); 
    comm.Parameters["NewLotteryChoices"].Value = newLotteryChoices; 
    try 
    { 
     conn.Open(); 
     comm.ExecuteNonQuery(); 
    } 
    finally 
    { 
     conn.Close(); 
    } 
    lottoFormDetails.ChangeMode(DetailsViewMode.ReadOnly); 
    BindLottoDetails(); 
} 


} 

的.aspx代码

<%@ Page Title="" Language="C#" MasterPageFile="~/admin.master" AutoEventWireup="true" CodeFile="adminDefault.aspx.cs" Theme="Blue" Inherits="adminDefault" %> 
<%@ Import Namespace = "System.Data.SqlClient" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" /> 
     <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script> 
    <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js" ></script> 
    <script> 
     $(function() { 
      $("#<%=datesearch.ClientID%>").datepicker(); 
     }); 
    </script> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 
    <div id="container"> 
     <div class="row"> 
      <div class="col-md-12"> 
       <h2>10th Mountain Lottery App</h2> 
      </div> 
     </div> 
     <div class="row"> 
      <div class="col-md-2 sidenav"> 
      <ul> 
       <li>Search Forms</li> 
       <li>Display Full Lottery List</li> 
       <li>Error Filtering</li> 
      </ul> 
     </div> 
      <div class="col-md-10"> 
       <p>You can use the menu below to search for individual forms</p> 
       <div class="row"> 
        <div class="col-md-10 col-md-offset-1"> 
         <h4>Lottery Form Search</h4> 
         <asp:Label runat="server">Search by Last Name: <asp:TextBox id="nameSearch" runat="server"></asp:TextBox></asp:Label> 
         <p><asp:Button id="nameSearchButton" runat="server" Text="Search" OnClick="lastNameButton" /></p> 

         <asp:Label runat="server">Search by Group Name: <asp:TextBox id="groupSearch" runat="server"></asp:TextBox></asp:Label> 
         <p><asp:Button id="groupsearchButton" runat="server" Text="Search" OnClick="groupNameButton" /></p> 
         <asp:Label runat="server">Search by Date: <asp:TextBox id="datesearch" runat="server"></asp:TextBox></asp:Label> 
         <p><asp:Button id="dateSearchButton" runat="server" Text="Search" OnClick="dateSearch" /></p> 
         <asp:Label ID="noMatchLabel" runat="server"></asp:Label> 
         <asp:GridView id="grid" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="grid_SelectedIndexChanged"> 
          <Columns> 
           <asp:BoundField DataField="First" HeaderText="First Name" /> 
           <asp:BoundField DataField="Last" HeaderText="Last Name" /> 
           <asp:BoundField DataField="C" HeaderText="City" /> 
           <asp:BoundField DataField="GroupName" HeaderText="Group Name" /> 
           <asp:ButtonField CommandName="Select" Text="Select" /> 
          </Columns> 
         </asp:GridView> 
         <br /> 
         <asp:DetailsView ID="lottoFormDetails" runat="server" AutoGenerateRows="False" OnItemUpdating="lottoFormDetails_ItemUpdating" OnModeChanging="lottoFormDetails_ModeChanging"> 
          <Fields> 
           <asp:TemplateField HeaderText="First Name"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editFirstTextBox" runat="server" Text='<%# Bind("First") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="insertFirstTextBox" runat="server" Text='<%# Bind("First") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="FirstLabel" runat="server" Text='<%# Bind("First") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="Last Name"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editLastTextBox" runat="server" Text='<%# Bind("Last") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="insertLastTextBox" runat="server" Text='<%# Bind("Last") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="LastLabel" runat="server" Text='<%# Bind("Last") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="Address"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editAddr1TextBox" runat="server" Text='<%# Bind("Addr1") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="insertAddr1TextBox" runat="server" Text='<%# Bind("Addr1") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="Addr1Label" runat="server" Text='<%# Bind("Addr1") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="City"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editCityTextBox" runat="server" Text='<%# Bind("C") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="insertCityTextBox" runat="server" Text='<%# Bind("C") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="CityLabel" runat="server" Text='<%# Bind("C") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="State"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editStateTextBox" runat="server" Text='<%# Bind("S") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="insertStateTextBox" runat="server" Text='<%# Bind("S") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="StateLabel" runat="server" Text='<%# Bind("S") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="Zip"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editZipTextBox" runat="server" Text='<%# Bind("Z") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="insertZipTextBox" runat="server" Text='<%# Bind("Z") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="ZipLabel" runat="server" Text='<%# Bind("Z") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="Daytime Phone #"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editdaytimephoneTextBox" runat="server" Text='<%# Bind("dayphone") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="insertdaytimephoneTextBox" runat="server" Text='<%# Bind("dayphone") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="daytimephoneLabel" runat="server" Text='<%# Bind("dayphone") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="Evening Phone #"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editeveningphoneTextBox" runat="server" Text='<%# Bind("eveningphone") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="inserteveningphoneTextBox" runat="server" Text='<%# Bind("eveningphone") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="eveningphoneLabel" runat="server" Text='<%# Bind("eveningphone") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="Email"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editemailTextBox" runat="server" Text='<%# Bind("email") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="insertemailTextBox" runat="server" Text='<%# Bind("email") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="emailLabel" runat="server" Text='<%# Bind("email") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="Membership"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editmembershipTextBox" runat="server" Text='<%# Bind("membership") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="insertmembershipTextBox" runat="server" Text='<%# Bind("membership") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="membershipLabel" runat="server" Text='<%# Bind("membership") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="Hut Credit"> 
            <EditItemTemplate> 
             <asp:TextBox ID="edithutCreditTextBox" runat="server" Text='<%# Bind("hutCredit") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="inserthutCreditTextBox" runat="server" Text='<%# Bind("hutCredit") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="hutCreditLabel" runat="server" Text='<%# Bind("hutCredit") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="Hut Credit Name"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editcreditNameTextBox" runat="server" Text='<%# Bind("creditName") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="insertcreditNameTextBox" runat="server" Text='<%# Bind("creditName") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="creditNameLabel" runat="server" Text='<%# Bind("creditName") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="Group Name"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editGroupNameTextBox" runat="server" Text='<%# Bind("GroupName") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="insertGroupNameTextBox" runat="server" Text='<%# Bind("GroupName") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="GroupNameLabel" runat="server" Text='<%# Bind("GroupName") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:TemplateField HeaderText="Lottery Choices"> 
            <EditItemTemplate> 
             <asp:TextBox ID="editLotteryChoicesTextBox" TextMode="multiline" Columns="75" Rows="10" runat="server" Text='<%# Bind("LotteryChoices") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <InsertItemTemplate> 
             <asp:TextBox ID="insertLotteryChoicesTextBox" TextMode="multiline" Columns="75" Rows="10" runat="server" Text='<%# Bind("LotteryChoices") %>'></asp:TextBox> 
            </InsertItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="LotteryChoicesLabel" TextMode="multiline" Columns="75" Rows="10" runat="server" Text='<%# Bind("LotteryChoices") %>'></asp:Label> 
            </ItemTemplate> 
           </asp:TemplateField> 
           <asp:CommandField ShowEditButton="True" /> 
          </Fields> 
          <HeaderTemplate> 
           <%#Eval("First")%> <%#Eval("Last") %> <%#Eval("dateTime") %> 
          </HeaderTemplate> 
         </asp:DetailsView> 

        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
</asp:Content 

>

+0

我认为你必须创建可以看着用于复制问题上最小的样品。 –

+1

*您可能*您的专栏有一个时间部分,您不是因素分解 - 您不能将datepicker日期(可能解析为'YYYY-MM-DDT00:00:00')等同于'DATETIME'包含时间的列('YYYY-MM-DDTHH:MM:SS')。您可能需要将您的搜索SQL更改为WHERE dateTime> = @ date1和dateTime <@ date2',并将'Date1'作为DateTime.Parse(datesearch.Text).Date'和'@ date2'作为DateTime .Parse(datesearch.Text).Date.AddDays(1)'在选定日期内切断时间部分和范围搜索。 – jimbobmcgee

+0

谢谢jimbobmcgee,那就是诀窍。尽管我确信西格蒙的答案也能奏效。我刚刚尝试过你。 – HiCntry

回答

1

在SQL中,你指出要存储数据作为日期时间。这意味着你得到日期和时间。当然,时间包括小时,分钟,秒等...

在您查询您需要CAST您的日期时间到一个日期,以消除它的时间。

看到这个MSDN文章更多的澄清https://msdn.microsoft.com/en-us/library/ms187819.aspx