I am writting an application in VB using VS2008 and SQL2005. I would like to save an array to my database and later retreive it. I understand that I need to serialize the array to do this but don't understand the process. I have looked at various resources on the Internet but seem to be missing something.

Would some one please provide me the code needed to serialize my array and then save it to my db. I am using stored procedures with paramaters to update my database.

Thanks.
Charles

>I need to serialize the array to do this but don't understand the process.

Dim no As Integer() = {11, 22, 33, 44}
        Dim MS As New System.IO.MemoryStream
        Dim bin As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
        bin.Serialize(MS, no)

        Dim bytes(MS.Length - 1) As Byte
        MS.Position = 0
        MS.Read(bytes, 0, bytes.Length)

        ....
        ...
        cmd.ComandText="insert into TableName values (@data)"
        cmd.Parameters.Add("@data", SqlDbType.Image, bytes.Length).Value = bytes
       ...

This is an excellant snippet which is really helpful, thanks. My biggest issue is not having worked with serialization. I kept getting lost at the point where , it appears, you store the serialized variable (bytes in your example) in the database.

Thanks
Charles

>I need to serialize the array to do this but don't understand the process.

Dim no As Integer() = {11, 22, 33, 44}
        Dim MS As New System.IO.MemoryStream
        Dim bin As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
        bin.Serialize(MS, no)

        Dim bytes(MS.Length - 1) As Byte
        MS.Position = 0
        MS.Read(bytes, 0, bytes.Length)

        ....
        ...
        cmd.ComandText="insert into TableName values (@data)"
        cmd.Parameters.Add("@data", SqlDbType.Image, bytes.Length).Value = bytes
       ...
This question has already been answered. Start a new discussion instead.