2014年7月13日 星期日

[RESOLVED] [C# net 4] Culture Info


Hello, hope in your help.


I've this code behind and I need display name of month in italian language.


protected void Page_Load(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("it-IT");

SQL = "SELECT ";
SQL = SQL + " DATE_FORMAT( ";
SQL = SQL + " STR_TO_DATE(Month, '%d/%m/%Y'), ";
SQL = SQL + " '%b, %Y' ";
SQL = SQL + ") AS Month, ";
SQL = SQL + " Number ";
SQL = SQL + " FROM ";
SQL = SQL + " tbl_u ";
SQL = SQL + "ORDER BY ";
SQL = SQL + " YEAR ( ";
SQL = SQL + " STR_TO_DATE(Month, '%d/%m/%Y') ";
SQL = SQL + " ) DESC, ";
SQL = SQL + " MONTH ( ";
SQL = SQL + " STR_TO_DATE(Month, '%d/%m/%Y') ";
SQL = SQL + " ) DESC; ";

try
{
OdbcCommand objCmd = new OdbcCommand(SQL, myConnectionString);
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = SQL;
objCmd.Connection = myConnectionString;

myConnectionString.Open();

....

Chart1.Series["Series1"].XValueMember = "Month";

....

Chart1.DataSource = objCmd.ExecuteReader();
Chart1.DataBind();

}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
myConnectionString.Close();
}
}

I add in code behind the:


Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("it-IT");

and in the aspx page:


<%@ Page Language="C#" Culture="it-IT" UICulture="it-IT" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

But the output for the `month` name is always english.


Can you help me?

Thank you.



I use this to display luglio


Label1.Text = DateTime.Now.ToString("MMMM", CultureInfo.GetCultureInfo("it-IT"));

Maybe you need to format the datetime in aspx page instead in sql



thank you, I tried this but I've error:


OdbcDataReader dr = objCmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
MonthYear = dr["Month"].ToString();
ItalianMonthYear = MonthYear.ToString("MMMM", CultureInfo.GetCultureInfo("it-IT"));
}
}
dr.Close();

Compiler Error Message: CS1501: No overload for method 'ToString' takes 2 arguments





I beleive there is better solution than this


OdbcDataReader dr = objCmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
DateTime dt=new DateTime(DateTime.Now.Year,Convert.ToInt32(dr["Month"]),1);
ItalianMonthYear = dt.ToString("MMMM", CultureInfo.GetCultureInfo("it-IT"));
}
}
dr.Close();







thanks a lot


沒有留言:

張貼留言