tags:

views:

75

answers:

1

Hi All,

How do I convert a C# Queue into a binary variable, so that I can store it as a blob in SQL?

Help appreciated!

Soham

+1  A: 

Look into Serialization. The easiest way might be to serialize the objects that are stored in the queue in their order, store them into your BLOB, then enqueue them on deserialization into a new Queue.

Axarydax
Yes, thanks Axary, I have thought about serialization. But then, how do I access and store the serialized data to be stored into a db table?
Soham
In C#, you could serialize something using BinarySerializer into a MemoryStream, then get MemoryStream's byte[] array and save that byte array into the database (BLOB=byte array)
Axarydax
thanks Axary. Much appreciated!
Soham
if this helped you, please accept my answer by the tick mark next to it.
Axarydax
AXARY, though I am in process of testing it, but I think this is going to work out well. So I have marked it as accepted answer. Any other roadblocks I am going to ask you :)
Soham
Axary,for binary serialization, a stream is required. Usually the streams I have worked with use a filestream and dump it in a .dat file or a .bin file for that matter. Is it possible to not dump in a file but in an SQL cell of type blob?
Soham
use MemoryStream that is mapped to memory. As I have said before, you can then "convert" the MemoryStream to byte array and save the byte array into the database
Axarydax
thanks, Yes I overlooked that part
Soham