I'm using dbase MySql with character encoding utf-8. The program is written on C#. IDE - SharpDevelop.
I use odbc to get some string data from dbase, but I get:
either symbols '?' if I don't set the charset to utf8 in my program via connection string or 'SET NAMES 'utf8''
or just strange symbols if I set the charset using one of the ways written above.
I looked in msdn, but I didn't find anything more about how I can set character set for obdc connection. Concerning mysql itself, I've set all charset variables to utf-8.
I use odbc to get some string data from dbase, but I get:
either symbols '?' if I don't set the charset to utf8 in my program via connection string or 'SET NAMES 'utf8''
or just strange symbols if I set the charset using one of the ways written above.
I looked in msdn, but I didn't find anything more about how I can set character set for obdc connection. Concerning mysql itself, I've set all charset variables to utf-8.
Code:
private void EstablishConnection()
{
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=building;" +
"UID=root;" +
"PASSWORD=arksoem;" +
"CHARSET=utf8;" +
"OPTION=6";
MyConnection = new OdbcConnection(MyConString);//"DNS=myodbc");
MyConnection.Open();
OdbcCommand com = new OdbcCommand("SELECT name FROM building_type",MyConnection);
// OdbcCommand com = new OdbcCommand("SET NAMES \'utf8\'",MyConnection);
// com.ExecuteNonQuery();
// string MyComString = "SELECT name FROM building_type";
// com.CommandText = MyComString;
OdbcDataReader dr = com.ExecuteReader();
textBox1.Text = "My string. Строка этакая на utf8.";
listBox1.BeginUpdate();
while(dr.Read())
{
string str = dr.GetString(0);
listBox1.Items.Add(str);
}
listBox1.EndUpdate();
MyConnection.Close();
}