Click here to Skip to main content
15,887,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have Database on localhost (xampp, mysql). I have some symbols cyrillics (russian symbols). All fields of database are setting as utf8mb4_general_ci. From Database I receive data to application CLR windows form (visual studio). It's work correctly. If I try change data at database from application, my string (with cyrillics) change to ??????????. English symbols are displayed correctly..

I add a reference MySql.Data to project CLR, then I write code.

I tried to change encoding from utf8 to cp1251 or cp866, but it didn't help.. I changed encoding MyForm.h to UTF8, but it didn't help also..

Help plz...

What I have tried:

C++
String^ constr = "Server=127.0.0.1;Uid=root;Pwd=;Database=travelagency;SSL Mode=None";
     MySqlConnection^ con = gcnew MySqlConnection(constr);
     String^ utf8 = "SET NAMES 'utf8'; SET CHARACTER SET 'utf8'; SET SESSION collation_connection = 'utf8_general_ci';";
     String^ sql_set = utf8 + "";

String^ fio = "Васильев Владимир Евгеньевич";
    String^ tel = "89161221111";
    String^ email = "ter@mail.ru";
    String^ adress = "г. Москва, Федоровская ул., д. 15";
    String^ sql_query = sql_set;
    sql_query += "insert into clients (fio, tel, email, adress) values('" + fio + "','" + tel + "','" + email + "','" + adress + "')";
    MySqlCommand^ cmd = gcnew MySqlCommand(sql_query, con);

    con->Open();
    MySqlDataReader^ dr = cmd->ExecuteReader();
    MessageBox::Show("Запись добавлена!");
    dr->Close();
    con->Close();
Posted
Updated 1-Sep-18 6:51am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900