简体   繁体   English

从字符串转换日期和/或时间时转换失败

[英]Conversion failed when converting date and /or time from character string

It seems error is appearing to convert the date or time. 似乎在转换日期或时间时出现错误。 I have two files result.aspx and result.aspx.cs. 我有两个文件result.aspx和result.aspx.cs。 The data will be displayed according to the given 1 day previous date in text box. 数据将根据给定的前一天日期在文本框中显示。 But it showing error. 但是显示错误。 More detail about error see this url http://playrajshrirashifal.com/result.aspx . 有关错误的更多详细信息,请参见此URL http://playrajshrirashifal.com/result.aspx Also you can download the code from here. 您也可以从此处下载代码。 http://playrajshrirashifal.com/test.zip http://playrajshrirashifal.com/test.zip

result.aspx code 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 code 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;
    }

} }

You must add a globalization section to the Web.config file, and then set the uiculture and culture attributes, as shown in the following example: 您必须将全球化部分添加到Web.config文件中,然后设置uiculture和区域性属性,如以下示例所示:

<globalization uiCulture="es" culture="es-MX" />

Table of Language Culture Names, Codes, and ISO Values Method 语言文化名称,代码和ISO值方法表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从字符串转换日期和/或时间时转换失败 - Conversion failed when converting date and /or time from character string 从字符串错误4转换日期和/或时间时转换失败 - Conversion failed when converting date and/or time from character string error 4 从字符串转换日期和/或时间时转换失败 - Conversion failed when converting date and/or time from character string 错误“从字符串转换日期和/或时间时转换失败” - Error “Conversion failed when converting date and/or time from character string” 从字符串转换日期和/或时间时,DateTime转换失败 - DateTime conversion failed when converting date and/or time from character string 问题:从字符串转换日期和/或时间时转换失败 - Problem: Conversion failed when converting date and/or time from character string 从字符串#2转换日期和/或时间时转换失败 - Conversion failed when converting date and/or time from character string #2 从字符串转换日期和/或时间时转换失败 - Conversion failed when converting date and/or time from character string 从Winforms中的字符串转换日期和/或时间时转换失败 - Conversion failed when converting date and/or time from character string in winforms 从字符串转换日期和/或时间时转换失败 - Conversion failed when converting date and/or time from character string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM