2016-05-31 60 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