Here is the code that can be used for converting a DataSet into its corresponding byte array. Sometimes when we need to send the data across the network through WCF service, we can get advantage of sending our data into a byte array. The reason behind to send the data in Byte Array format is that byte array is the one of the primitive data type available in .Net
private byte[] ConvertDataSetToByteArray(DataSet dataSet)
{
byte[] binaryDataResult = null;
using (MemoryStream memStream = new MemoryStream())
{
BinaryFormatter brFormatter = new BinaryFormatter();
dataSet.RemotingFormat = SerializationFormat.Binary;
brFormatter.Serialize(memStream, dataSet);
binaryDataResult = memStream.ToArray();
}
return binaryDataResult;
}