Reputation: 31
I use C# web service to insert, delete and get data from MySql database. The problem is some of the data is in Macedonian (Cyrilic).
When I insert directly in the database, it inserts ok. For example: "дсд" is "дсд". When I insert throgh the service, it's not. For example: "дсд" is "???". When I try to get data throug the service, it gets it ok. What's the problem with the inserting?
Here is part of my code for inserting:
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
command.CommandText = "INSERT INTO user (id_user, name VALUES (NULL, ?name);";
command.Parameters.Add("?name", MySqlDbType.VarChar).Value = name;
connection.Open();
command.ExecuteReader();
connection.Close();
return thisrow;
Tnq U in advance!!!
Upvotes: 1
Views: 1652
Reputation: 31
The solution is in the connection string: MyConString = "SERVER=localhost;" + "DATABASE=yourdatabase;" + "charset=utf8;";.
Upvotes: 2
Reputation: 71563
I would look at the encoding for the web service itself. The problem may be in turning the text into a SOAP string to send to the service. String data is Unicode by default in .NET, so once it gets to the web service it should be fine.
To verify that this is the problem, attach a debugger to the method that has your code snippet and seta breakpoint at or around adding the parameter. The string "name" that you're assigning to the parameter should show up correctly in the Watch or Locals window. If it doesn't, your code did not receive the string you're expecting, which probably means that your clients are encoding in ASCII or an ISO codepage other than Cyrillic.
Upvotes: 0