I’m having difficulty saving international characters in my MySQL database while using VB.NET. My application needs to support various languages, including Chinese, Japanese, Arabic, and Russian text.
When I enter foreign characters in my Windows form, they show up correctly. But after saving to the database, I only see question marks (???) instead of the intended characters. I’ve already attempted to change the database collation to UTF8, but the issue continues.
Here’s the code I’m using for insertion:
sqlQuery = "INSERT INTO events.event_info (event_name, host_name, schedule_date, start_time, end_time, location, image_data, creator_id, created_on) " & _
"VALUES(@event_name, @host_name, @schedule_date, @start_time, @end_time, @location, @image_data, @creator_id, @created_on);"
dbConnection = New MySqlClient.MySqlConnection(config.connectionString)
formattedDate = Format(eventData.scheduleDate, "yyyy-MM-dd")
dbConnection.Open()
With dbCommand
.CommandText = sqlQuery
.Connection = dbConnection
.Parameters.AddWithValue("@event_name", eventData.eventTitle)
.Parameters.AddWithValue("@host_name", eventData.hostName)
.Parameters.AddWithValue("@schedule_date", formattedDate)
.Parameters.AddWithValue("@start_time", eventData.startTime)
.Parameters.AddWithValue("@end_time", eventData.endTime)
.Parameters.AddWithValue("@location", eventData.venue)
.Parameters.AddWithValue("@image_data", eventData.logoBytes)
.Parameters.AddWithValue("@creator_id", currentUser.userId)
.Parameters.AddWithValue("@created_on", Format(Now, "yyyy-MM-dd HH:mm:ss"))
recordsAffected = .ExecuteNonQuery()
End With
When trying to insert Russian text, I encounter this error: “Incorrect string value: ‘\xD1\x84\xD0\xBA\xD1\x83…’ for column ‘event_name’ at row 1”
What’s the right way to set the database collation and connection settings to ensure support for multilingual text input?