我在MySQL數據庫連接的c#應用程序中設置語言有問題。在c#應用程序中設置語言
正在使用的服務器是英文版的Windows Server 2003。
我需要設置德語的查詢輸出。
我試過MySQL數據庫中的查詢序列,輸出是正確的。
mysql> SET lc_time_names = 'de_DE';
SELECT
CONCAT(
MONTHNAME(
STR_TO_DATE(Eng_Month, '%Y-%m')
),
' ',
YEAR (
STR_TO_DATE(Eng_Month, '%Y')
)
) AS DE_Date
FROM
tbl_month;
Query OK, 0 rows affected
+-----------+
| DE_Date |
+-----------+
| Juni 2014 |
| Juli 2014 |
+-----------+
2 rows in set
如果在c#應用程序中嘗試相同的解決方案,輸出只是英文。
這開始讓我相信我的整個結構是不正確的。
我缺少什麼?
我將不勝感激任何幫助,您可以給我在工作的這個問題。
我下面的代碼:
protected override void InitializeCulture()
{
Page.Culture = "de-DE";
Page.UICulture = "de-DE";
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitializeCulture();
MonthLanguage();
GridViewBind();
Response.Write(Page.Culture + "<br />");
Response.Write("Your current culture: " + System.Globalization.CultureInfo.CurrentCulture.DisplayName + "<br />");
}
}
protected void MonthLanguage()
{
using (OdbcConnection cn =
new OdbcConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
{
sql = " SET lc_time_names = 'de_DE'; ";
using (OdbcCommand command =
new OdbcCommand(sql, cn))
{
try
{
command.Connection.Open();
command.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new ApplicationException("operation failed!", ex);
}
finally
{
command.Connection.Close();
}
}
}
}
public DataTable GridViewBind()
{
sql = " ... ";
try
{
dadapter = new OdbcDataAdapter(sql, cn);
dset = new DataSet();
dset.Clear();
dadapter.Fill(dset);
DataTable dt = dset.Tables[0];
GridView1.DataSource = dt;
GridView1.DataBind();
return dt;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dadapter.Dispose();
dadapter = null;
cn.Close();
}
}
謝謝你,在MySQL不行你的建議 – 2014-09-11 08:13:26