We have data in serialized form of binary.Now we have to store it in PostGre database.
For insertion , we had stored the code in data column of bytea .
And use the following code:
using (FileStream pgFileStream = new FileStream("F:\\Test.abc", FileMode.Open, FileAccess.Read))
{
using (BinaryReader pgReader = new BinaryReader(new BufferedStream(pgFileStream)))
{
NpgsqlCommand command = new NpgsqlCommand();
byte[] ByteA = pgReader.ReadBytes(Convert.ToInt32(pgFileStream.Length));
command.CommandText = "insert into ptadata (memberid, filedata) VALUES (03, @data)";
command.Connection = m_IDBcloudConnection;
if (m_IDBcloudConnection.State != ConnectionState.Open)
{
m_IDBcloudConnection.Open();
}
command.Parameters.Add("@data", ByteA).Value = ByteA;
command.ExecuteNonQuery();
m_IDBcloudConnection.Close();
}
}
But when we try to retrieve it ,comes in the form of byte.
How can I get the data in serialized form of binary?
What I have tried:
using (FileStream pgFileStream = new FileStream("F:\\Test.abc", FileMode.Open, FileAccess.Read))
{
using (BinaryReader pgReader = new BinaryReader(new BufferedStream(pgFileStream)))
{
NpgsqlCommand command = new NpgsqlCommand();
byte[] ByteA = pgReader.ReadBytes(Convert.ToInt32(pgFileStream.Length));
command.CommandText = "insert into ptadata (memberid, filedata) VALUES (03, @data)";
command.Connection = m_IDBcloudConnection;
if (m_IDBcloudConnection.State != ConnectionState.Open)
{
m_IDBcloudConnection.Open();
}
command.Parameters.Add("@data", ByteA).Value = ByteA;
command.ExecuteNonQuery();
m_IDBcloudConnection.Close();
}
}