Home > Articles > How to convert DataTable to stream in C#

How to convert DataTable to stream in C#

In socket programming, we do not only send data in the form of text. Sometimes, we send data from database or for database processing . In that case, we need to format data as streams.
The First thing we should do is serializing data as stream and then send it as a single piece of data. The App server receive data then deserialize it as DataTable.
This article discusses about how to serialize and deserialize data as stream using c # …

public byte[] SerializeData(Object o)
 MemoryStream ms = new MemoryStream();
 BinaryFormatter bf1 = new BinaryFormatter();
 bf1.Serialize(ms, o);
 return ms.ToArray();

public object DeserializeData(byte[] theByteArray)
 MemoryStream ms = new MemoryStream(theByteArray);
 BinaryFormatter bf1 = new BinaryFormatter();
 ms.Position = 0;
 return bf1.Deserialize(ms);
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: