我在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