Forum » Programiranje » C# - MySQL - šumniki
C# - MySQL - šumniki
Matthew ::
V C# razvijam aplikacijo, ki shranjuje podatke v MySQL bazi. Žal imam težave s šumniki. 'čžš' mi zapiše v bazo kot 'czs'.
SHOW VARIABLES LIKE 'character_set%' vrne:
Variable_name Value
character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
character_sets_dir /usr/share/mysql/charsets/
SHOW VARIABLES LIKE 'collation%' vrne:
Variable_name Value
collation_connection utf8_general_ci
collation_database utf8_slovenian_ci
collation_server latin1_swedish_ci
Baza ima collation utf8_slovenian_ci.
Tabela ima collation utf8_slovenian_ci.
Polje v tabeli, v katerega pišem ima collation utf8_slovenian_ci.
Koda, s katero pišem v bazo je sledeča:
using MySql.Data.MySqlClient;
String MyConString = "SERVER=192.168.x.x;" + "DATABASE=xxxx;" + "UID=xxxx;" + "PASSWORD=xxxx;";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
connection.Open();
command.CommandText = "SET NAMES utf8";
command.ExecuteNonQuery();
command.CommandText = "SET CHARACTER SET utf8";
command.ExecuteNonQuery();
command.CommandText = "SET COLLATION_CONNECTION=utf8_general_ci";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO test(id_test, tekst) VALUES ('', 'čžš')";
command.ExecuteNonQuery();
connection.Close();
Zelo bi bil hvalažen, če bi mi kdo pomagal pri problemu, ker meni se je tukaj ustavilo.
SHOW VARIABLES LIKE 'character_set%' vrne:
Variable_name Value
character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
character_sets_dir /usr/share/mysql/charsets/
SHOW VARIABLES LIKE 'collation%' vrne:
Variable_name Value
collation_connection utf8_general_ci
collation_database utf8_slovenian_ci
collation_server latin1_swedish_ci
Baza ima collation utf8_slovenian_ci.
Tabela ima collation utf8_slovenian_ci.
Polje v tabeli, v katerega pišem ima collation utf8_slovenian_ci.
Koda, s katero pišem v bazo je sledeča:
using MySql.Data.MySqlClient;
String MyConString = "SERVER=192.168.x.x;" + "DATABASE=xxxx;" + "UID=xxxx;" + "PASSWORD=xxxx;";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
connection.Open();
command.CommandText = "SET NAMES utf8";
command.ExecuteNonQuery();
command.CommandText = "SET CHARACTER SET utf8";
command.ExecuteNonQuery();
command.CommandText = "SET COLLATION_CONNECTION=utf8_general_ci";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO test(id_test, tekst) VALUES ('', 'čžš')";
command.ExecuteNonQuery();
connection.Close();
Zelo bi bil hvalažen, če bi mi kdo pomagal pri problemu, ker meni se je tukaj ustavilo.
Matthew ::
Spremenil sem vrstico z SQL-om v:
command.CommandText = "INSERT INTO test(id_test, tekst) VALUES ('', CONVERT('čžš' USING utf8))";
Še vedno isto.
command.CommandText = "INSERT INTO test(id_test, tekst) VALUES ('', CONVERT('čžš' USING utf8))";
Še vedno isto.
Matthew ::
Tip polja v tabeli sem spremenil v Text.
INSERT stavek sem spremenil v "INSERT INTO test(id_test, tekst) VALUES('', N'čžš')".
Še vedno dobim czs :/
INSERT stavek sem spremenil v "INSERT INTO test(id_test, tekst) VALUES('', N'čžš')".
Še vedno dobim czs :/
Matthew ::
Končno sem našel rešitev. Connection String-u sem dodal še "charset=utf8;".
String MyConString = "SERVER=192.168.x.x;" + "DATABASE=xxxx;" + "UID=xxxx;" + "PASSWORD=xxxx;" + "charset=utf8;";
String MyConString = "SERVER=192.168.x.x;" + "DATABASE=xxxx;" + "UID=xxxx;" + "PASSWORD=xxxx;" + "charset=utf8;";
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | [php] encoding nizaOddelek: Izdelava spletišč | 3822 (1737) | BivšiUser2 |
» | [c#] in sql bazaOddelek: Programiranje | 1385 (884) | japol |
» | SQL problemOddelek: Programiranje | 1702 (1320) | win64 |
» | Šumniki in MySqlOddelek: Izdelava spletišč | 6688 (6225) | SPEEEED |
» | MySQL in czsOddelek: Izdelava spletišč | 3611 (2701) | krho |