Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

IBinarySerialize.Write Method

Converts a user-defined type (UDT) or user-defined aggregate into its binary format so that it may be persisted.

Namespace:  Microsoft.SqlServer.Server
Assembly:  System.Data (in System.Data.dll)
void Write(
	BinaryWriter w
)

Parameters

w
Type: System.IO.BinaryWriter

The BinaryWriter stream to which the UDT or user-defined aggregate is serialized.

Write sufficient information to the binary stream to allow the Read method to reconstitute your UDT or user-defined aggregate.

The following example shows the implementation of the Writemethod of a UDT, which uses a BinaryWriter to serialize the UDT in the user-defined binary format. The purpose of the null character padding is to ensure that the string value is completely separated from the double value, so that one UDT is compared to another in Transact-SQL code, string bytes are compared to string bytes and double bytes are compared to double bytes.

// The binary layout is as follows: 
//    Bytes 0 - 19: string text, padded to the right with null characters 
//    Bytes 20+: Double value 
public void Write(System.IO.BinaryWriter w)
{        
    int maxStringSize = 20;
    string stringValue = "The value of PI: ";
    string paddedString; 
    double value = 3.14159;

    // Pad the string from the right with null characters.
    paddedString = stringValue.PadRight(maxStringSize, '\0');

    // Write the string value one byte at a time. 
    for (int i = 0; i < paddedString.Length; i++)
    {
        w.Write(paddedString[i]);
    }

    // Write the double value.
    w.Write(value);
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.