dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlConnection Class / Unicode Property
Example

In This Topic
    Unicode Property (MySqlConnection)
    In This Topic
    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.
    Remarks
    Sets MySQL client charset to UTF8 and converts client data according to this charset.

    When a value is assigned to this property, the MySqlConnection is closed.

    MySQL server version 4.1 or higher is required to use this option.
    Example
    The following two functions demonstrate how to use Unicode property to implement charset-safe string transfer.
    public void UploadString(MySqlConnection myConnection)
    {
      myConnection.Unicode = true;
      MySqlCommand myCommand = new MySqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(1,'First',:BlockText)", myConnection);
      myCommand.Parameters.Add("BlockText",MySqlType.VarChar,50).Value = "Place here some text that requires Unicode support.";
      myConnection.Open();
      try
      {
        Console.WriteLine(myCommand.ExecuteNonQuery()+" rows affected.");
      }
      finally
      {
        myConnection.Close();
      }
    }                                                                                                                                           
    
    public void DownloadString(MySqlConnection myConnection)
    {
      myConnection.Unicode = true;
      MySqlCommand myCommand = new MySqlCommand("SELECT * FROM Test.TextBlocks", myConnection);
      myConnection.Open();
      MySqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.Default);
      try
      {
        while (myReader.Read())
        {
          string myString = (string)myReader["BlockContent"];
          Console.WriteLine(myString);
        }
      }
      finally
      {
        myReader.Close();
        myConnection.Close();
      }
    }
    Public Sub UploadString(ByVal myConnection As MySqlConnection)
      myConnection.Unicode = True
      Dim myCommand As New MySqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(1,'First',:BlockText)", myConnection)
      myCommand.Parameters.Add("BlockText", MySqlType.VarChar, 50).Value = "Place here some text that requires Unicode support."
      myConnection.Open()
      Try
        Console.WriteLine(String.Concat(myCommand.ExecuteNonQuery(), " rows affected."))
      Finally
        myConnection.Close()
      End Try
    End Sub
    
    Public Sub DownloadString(ByVal myConnection As MySqlConnection)
    
      myConnection.Unicode = True
      Dim myCommand As New MySqlCommand("SELECT * FROM Test.TextBlocks", myConnection)
      myConnection.Open()
      Dim myReader As MySqlDataReader = myCommand.ExecuteReader(CommandBehavior.Default)
      Try
        While myReader.Read()
          Dim myString As String = CType(myReader("BlockContent"), String)
          Console.WriteLine(myString)
        End While
      Finally
        myReader.Close()
        myConnection.Close()
      End Try
    End Sub
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also