Unicode Property (MySqlConnection)
On this page
Gets or sets a value indicating whether the UTF8 charset will be used.
Syntax
|
|---|
'Declaration
Public Property Unicode As Boolean |
|
|---|
public bool Unicode {get; set;} |
Property Value
true, if client charset UTF8 is used;
false, if default client charset is used. The default value is
false.
Example
The following two functions demonstrate how to use
Unicode property to implement charset-safe string transfer.
|
|---|
public void UploadString(MySqlConnection mySqlConnection)
{
mySqlConnection.Unicode = true;
MySqlCommand mySqlCommand = new MySqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(1,'First',:BlockText)", mySqlConnection);
mySqlCommand.Parameters.Add("BlockText",MySqlType.VarChar,50).Value = "Place here some text that requires Unicode support.";
mySqlConnection.Open();
try
{
Console.WriteLine(mySqlCommand.ExecuteNonQuery()+" rows affected.");
}
finally
{
mySqlConnection.Close();
}
}
public void DownloadString(MySqlConnection mySqlConnection)
{
mySqlConnection.Unicode = true;
MySqlCommand mySqlCommand = new MySqlCommand("SELECT * FROM Test.TextBlocks", mySqlConnection);
mySqlConnection.Open();
MySqlDataReader mySqlReader = mySqlCommand.ExecuteReader(CommandBehavior.Default);
try
{
while (mySqlReader.Read())
{
string myString = (string)mySqlReader["BlockContent"];
Console.WriteLine(myString);
}
}
finally
{
mySqlReader.Close();
mySqlConnection.Close();
}
} |
|
|---|
Public Sub UploadString(ByVal mySqlConnection As MySqlConnection)
mySqlConnection.Unicode = True
Dim mySqlCommand As New MySqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(1,'First',:BlockText)", mySqlConnection)
mySqlCommand.Parameters.Add("BlockText", MySqlType.VarChar, 50).Value = "Place here some text that requires Unicode support."
mySqlConnection.Open()
Try
Console.WriteLine(String.Concat(mySqlCommand.ExecuteNonQuery(), " rows affected."))
Finally
mySqlConnection.Close()
End Try
End Sub
Public Sub DownloadString(ByVal mySqlConnection As MySqlConnection)
mySqlConnection.Unicode = True
Dim mySqlCommand As New MySqlCommand("SELECT * FROM Test.TextBlocks", mySqlConnection)
mySqlConnection.Open()
Dim mySqlReader As MySqlDataReader = mySqlCommand.ExecuteReader(CommandBehavior.Default)
Try
While mySqlReader.Read()
Dim myString As String = CType(mySqlReader("BlockContent"), String)
Console.WriteLine(myString)
End While
Finally
mySqlReader.Close()
mySqlConnection.Close()
End Try
End Sub |
See Also