steavy
steavy

Reputation: 1576

when inserting cyrillic values into MySQL db values they appear to be "?????"

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

Answers (2)

Edward Ruchevits
Edward Ruchevits

Reputation: 6696

  1. Be sure to use UTF8 as database collation.

  2. Try this immediately after opening connection:

    con.ConnectionString = "database=DATABASE;server=localhost;user id=USERNAME;pwd=PASSWORD;CharSet=utf8"; after creating connection.

Upvotes: 3

Fish Biscuit
Fish Biscuit

Reputation: 133

as per This Post you might need to do this:

ALTER TABLE tablename CHARACTER SET utf8 COLLATE utf8_general_ci;

Upvotes: 0

Related Questions