Question Special characters in mysql

Joined
Jun 11, 2016
Messages
16
Location
Sweden
Programming Experience
1-3
So i have made a online chat using mysql and now im working on emoji support. The emojis are unicode characters. When i send a message to the server/database it only outputs as "??" ( without the quotes btw ). First, the unicode is inserted too the textbox then sends the message with the characters to the mysql db. Then the listbox gets the content of the mysql table. The table collation is utf8mb4_general_ci, and heres the connection string:
Protected con As New MySqlConnection("host=sql7.freemysqlhosting.net; username=sql7; password=xyz; database=sql; character set=utf8")

here is the mysql command text;
cmd2.CommandText = "SET NAMES UTF8; SET CHARACTER SET UTF8; insert into chat(message) values ('[Admin] " & Form1.usern.Text & ": " & msgtxt.Text & "')"

Any idea how to fix this?
 
Last edited by a moderator:
Don't use string concatenation to insert values into SQL code. Always use parameters and then there are no issues with reserved words or spaces or other special characters and, most importantly, you're safe from SQL injection. Follow the Blog link in my signature below and check out my post on Parameters In ADO.NET for more information on why and how.
 
Back
Top