S
Sergei Shelukhin
I have the following problem with gridview. I use MySQL database that
has Russian characters in cp1251 encoding, and I get ????????s instead
of Russian characters on all my ASP.NET pages.
To fix this, I use helper function to get database connection, it goes:
public static OdbcConnection GetConnection()
{
OdbcConnection cn = new
OdbcConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
OdbcCommand cmd = new OdbcCommand("set
character_set_client='cp1251'",cn);
cn.Open();
cmd.ExecuteNonQuery();
cmd.CommandText = "set character_set_results='cp1251'";
cmd.ExecuteNonQuery();
cmd.CommandText = "set collation_connection='cp1251_general_ci'";
cmd.ExecuteNonQuery();
return cn;
}
It works well for all my pages, components etc.
Gridview, however, uses its own means to get the connection so it still
gets ????s; to fix it, I use the following:
protected override void OnPreRender(EventArgs e)
{
if (!IsPostBack)
{
OdbcConnection cn = SEHelper.GetConnection();
cn.Close();
GridView1.DataBind();
}
base.OnPreRender(e);
}
For some reason (connection pooling? some session kept between mysql
and aspnet? odbc driver quirks?) everything works perfectly well with
this code but it's kinda ugly, so, I have the following questions:
1) Is there any way to change connection used to get data into
SqlDataSource before it binds to data?
2) If there's none, is there any way to run commands against the
connection it uses before it binds?
3) If that's not possible too, is there any way to disable default
databinding of GridView/SqlDataSource combo to save extra trip to the
datatbase, given that I always have to rebind the gridview anyway?
has Russian characters in cp1251 encoding, and I get ????????s instead
of Russian characters on all my ASP.NET pages.
To fix this, I use helper function to get database connection, it goes:
public static OdbcConnection GetConnection()
{
OdbcConnection cn = new
OdbcConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
OdbcCommand cmd = new OdbcCommand("set
character_set_client='cp1251'",cn);
cn.Open();
cmd.ExecuteNonQuery();
cmd.CommandText = "set character_set_results='cp1251'";
cmd.ExecuteNonQuery();
cmd.CommandText = "set collation_connection='cp1251_general_ci'";
cmd.ExecuteNonQuery();
return cn;
}
It works well for all my pages, components etc.
Gridview, however, uses its own means to get the connection so it still
gets ????s; to fix it, I use the following:
protected override void OnPreRender(EventArgs e)
{
if (!IsPostBack)
{
OdbcConnection cn = SEHelper.GetConnection();
cn.Close();
GridView1.DataBind();
}
base.OnPreRender(e);
}
For some reason (connection pooling? some session kept between mysql
and aspnet? odbc driver quirks?) everything works perfectly well with
this code but it's kinda ugly, so, I have the following questions:
1) Is there any way to change connection used to get data into
SqlDataSource before it binds to data?
2) If there's none, is there any way to run commands against the
connection it uses before it binds?
3) If that's not possible too, is there any way to disable default
databinding of GridView/SqlDataSource combo to save extra trip to the
datatbase, given that I always have to rebind the gridview anyway?