dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlBinaryString Structure
Members Example

In This Topic
    MySqlBinaryString Structure
    In This Topic
    Represents MySQL BINARY and VARBINARY types.
    Syntax
    Remarks
    This structure manages BINARY and VARBINARY as strings with certain encoding (specified with the Encoding property).
    Example
    The following example demonstrates how to insert and fetch text data using binary types.
    MySqlCommand insertCommand = new MySqlCommand("insert into autotest.simple_types (f_binary, f_varbinary) values (:p1, :p2)", connection);
    
    Encoding encoding = Encoding.Unicode;
    byte[] buffer1 = encoding.GetBytes("test1");
    byte[] buffer2 = encoding.GetBytes("test2");
    
    insertCommand.Parameters.Add("p1", new MySqlBinaryString(buffer1, encoding));
    insertCommand.Parameters.Add("p2", new MySqlBinaryString(buffer2, encoding));
    insertCommand.ExecuteNonQuery();
    
    MySqlCommand selectCommand = new MySqlCommand("select f_binary, f_varbinary from autotest.simple_types", connection);
    
    using (MySqlDataReader reader = selectCommand.ExecuteReader())
     while (reader.Read())
       for (int i = 0; i < reader.FieldCount; ++i) {
         MySqlBinaryString value = (MySqlBinaryString)reader.GetProviderSpecificValue(i);
         value.Encoding = encoding;
         Console.WriteLine(value);
       }
    Inheritance Hierarchy

    System.Object
       System.ValueType
          Devart.Data.MySql.MySqlBinaryString

    See Also