0
看起來轉換日期或時間出現錯誤。我有兩個文件result.aspx和result.aspx.cs。數據將根據給定的前一天的日期在文本框中顯示。但它顯示錯誤。有關錯誤的更多詳細信息,請參閱此網址http://playrajshrirashifal.com/result.aspx。你也可以從這裏下載代碼。 http://playrajshrirashifal.com/test.zip從字符串中轉換日期和/或時間時轉換失敗
result.aspx代碼
<asp:DataList ID="DataList3" runat="server" DataKeyField="Id" DataSourceID="SqlDataSource1">
<asp:DataList ID="DataList2" runat="server" DataKeyField="Id" DataSourceID="SqlDataSource2">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:rajshriConnectionString %>" SelectCommand="SELECT [Id], [LotteryA], [LotteryB], [LotteryC], [Time], [Date] FROM [lottery] WHERE ((CAST([Date] as DATE) = @Date) AND (CAST([Time] as TIME) <= @Time))">
<SelectParameters>
<asp:ControlParameter ControlID="Label2" Name="Date" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="Label1" Name="Time" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:rajshriConnectionString %>" SelectCommand="SELECT [Id], [LotteryA], [LotteryB], [LotteryC], [Time], [Date] FROM [lottery] WHERE ((CAST([Date] as DATE) = @Date) AND (CAST([Date] as DATE) < @Date2))">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="Date" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="Label2" PropertyName="Text" Name="Date2" Type="String"></asp:ControlParameter>
</SelectParameters>
</asp:SqlDataSource>
</form>
result.aspx.cs代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class result : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString("t");
Label2.Text = DateTime.Now.ToString("d");
}
protected void Button1_OnClick(object sender, EventArgs e)
{
DataList3.Visible = false;
asd.Visible = false;
}
}
添加,但不solving.it顯示以前的錯誤。 – swdpankaj
你在調試模式下運行嗎?在Web.debug.config中添加。 – KreminT