【发布时间】:2014-08-04 09:54:27
【问题描述】:
在我的 server windows 2003 中,默认语言和安装是 english 语言。
现在我需要用 西班牙语 显示我的 aspx 页面的 GridView。
我已经尝试过这个代码隐藏,但 GridView 中的输出始终是英文,即使我尝试运行 查询 strSQL 时也会出现错误,为什么?
ExecuteNonQuery requires an open and available Connection.
The connection's current state is closed.
下面是我的代码。
非常感谢您在解决这个问题时能给我的任何帮助。 提前谢谢你。
public DataTable GridViewBind()
{
sql = " SELECT * from .... ; ";
try
{
dadapter = new OdbcDataAdapter(sql, conn);
dset = new DataSet();
dset.Clear();
dadapter.Fill(dset);
DataTable dt = dset.Tables[0];
GridView1.DataSource = dt;
string strSQL = " SET lc_time_names = 'es_ES'; ";
OdbcCommand cmd = new OdbcCommand(strSQL, conn);
cmd.ExecuteNonQuery();
GridView1.DataBind();
return dt;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dadapter.Dispose();
dadapter = null;
conn.Close();
}
}
protected override void InitializeCulture()
{
Page.Culture = "es-ES";
Page.UICulture = "es-ES";
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
InitializeCulture();
GridViewBind();
}
}
编辑 1
conn.Open();
string strSQL = " SET lc_time_names = 'es_ES'; ";
OdbcCommand cmd = new OdbcCommand(strSQL, conn);
cmd.ExecuteNonQuery();
【问题讨论】:
-
错误消息说明了问题所在。您的连接已关闭。它必须是开放的。
-
谢谢,我的第一篇文章中有 EDIT 1,现在的错误是连接未关闭。连接的当前状态是打开
-
我在下面提出了一个问题,但显然它没有回答这个问题,所以它已被删除!我想包含一些来自 OP 帖子的代码——在这些 cmets 框中你不能轻易做到这一点。那么,如果您无法查询代码,您将如何提供帮助?我不想编辑 OP 的代码 - 这只会让人困惑