S
Ste
Hi group,
having done some searching on Google i have managed to save an
instance of my class to a database by first serializing it to a file.
The question i have is: can i do this without having to use a temporary
file ?
Here is the code i'm using:
'Serialize class to filestream
Dim formatter As New
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim stream As New System.IO.FileStream("Input.bin",
System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite,
System.IO.FileShare.None)
formatter.Serialize(stream, usrPallets)
'Declare a byte array to save the content of the file to be saved
Dim FileByteArray(stream.Length - 1) As Byte
stream.Read(FileByteArray, 0, stream.Length)
'Add parameter to odbc command
cmdTest.Parameters.Clear()
cmdTest.Parameters.Add(New Microsoft.Data.Odbc.OdbcParameter("Test",
Microsoft.Data.Odbc.OdbcType.Binary, stream.Length,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"PALLET", System.Data.DataRowVersion.Current, ""))
cmdTest.Parameters(0).Value = FileByteArray
stream.Close()
'Run SQL insert statement
conTESTSS.Open()
cmdTest.ExecuteNonQuery()
conTESTSS.Close()
TIA,
Ste..
having done some searching on Google i have managed to save an
instance of my class to a database by first serializing it to a file.
The question i have is: can i do this without having to use a temporary
file ?
Here is the code i'm using:
'Serialize class to filestream
Dim formatter As New
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim stream As New System.IO.FileStream("Input.bin",
System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite,
System.IO.FileShare.None)
formatter.Serialize(stream, usrPallets)
'Declare a byte array to save the content of the file to be saved
Dim FileByteArray(stream.Length - 1) As Byte
stream.Read(FileByteArray, 0, stream.Length)
'Add parameter to odbc command
cmdTest.Parameters.Clear()
cmdTest.Parameters.Add(New Microsoft.Data.Odbc.OdbcParameter("Test",
Microsoft.Data.Odbc.OdbcType.Binary, stream.Length,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"PALLET", System.Data.DataRowVersion.Current, ""))
cmdTest.Parameters(0).Value = FileByteArray
stream.Close()
'Run SQL insert statement
conTESTSS.Open()
cmdTest.ExecuteNonQuery()
conTESTSS.Close()
TIA,
Ste..