Reputation: 1576
I am using ado.net and MySQL db. When I insert cyrillic values into db, they are inserted as '?' symbols. I have tried various encodings in db, this didn`t help. I tried utf-8, utf-16, cp-1251 and many others. So when I execute this code
MySql.Data.MySqlClient.MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection("server=localhost;User Id=root;database=voteme");
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("INSERT INTO districts(DistrictName) VALUES('іавп')",con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
I receive '????' stored in my db. How do I solve this problem? Thanks.
Edit: I tried to use both varchar and text field types in database: result was still the same.
Upvotes: 1
Views: 675
Reputation: 6696
Be sure to use UTF8 as database collation.
Try this immediately after opening connection:
con.ConnectionString = "database=DATABASE;server=localhost;user id=USERNAME;pwd=PASSWORD;CharSet=utf8"; after creating connection.
Upvotes: 3
Reputation: 133
as per This Post you might need to do this:
ALTER TABLE tablename CHARACTER SET utf8 COLLATE utf8_general_ci;
Upvotes: 0