M
Markusek Peter
Hi,
I'm using MySQLDriverCS. I've got no problem to store BLOB into database,
but I can't get it back(save to file).
Problem is with DataTable(returns string
)
My code:
--
DataTable dt = new MySQLSelectCommand(...; //select that row and column
where is BLOB
string dest = Server.MapPath("image.jpg");
FileStream binFile = new
FileStream(dest,FileMode.OpenOrCreate,FileAccess.Write);
--
Now I want to use - binFile.Write(buf,0,buf.Length);. But problem is that
dt.Rows[0]["ColumnBLOB"] is System.String type, and I need byte[](for
binFile.Write)
When I use this function :
--
public byte[] Serialize(object o)
{
MemoryStream s = new MemoryStream();
BinaryFormatter b = new BinaryFormatter();
b.Serialize(s, o);
if (s.Length > int.MaxValue)
throw new ArgumentException("Serialized object is larger than can fit into
byte array");
byte[] buffer = new Byte[s.Length];
s.Seek(0, SeekOrigin.Begin);
s.Read(buffer, 0, (int)s.Length);
s.Close();
return buffer;
}
--
BLOB is saved into the file with the right size, but most of the characters
are '?'(because
dt.Rows[0]["ColumnBLOB"] is string?)
=====================
I'm sorry for bad english.
Sample code will be appreciated
Thanks.
I'm using MySQLDriverCS. I've got no problem to store BLOB into database,
but I can't get it back(save to file).
Problem is with DataTable(returns string

My code:
--
DataTable dt = new MySQLSelectCommand(...; //select that row and column
where is BLOB
string dest = Server.MapPath("image.jpg");
FileStream binFile = new
FileStream(dest,FileMode.OpenOrCreate,FileAccess.Write);
--
Now I want to use - binFile.Write(buf,0,buf.Length);. But problem is that
dt.Rows[0]["ColumnBLOB"] is System.String type, and I need byte[](for
binFile.Write)
When I use this function :
--
public byte[] Serialize(object o)
{
MemoryStream s = new MemoryStream();
BinaryFormatter b = new BinaryFormatter();
b.Serialize(s, o);
if (s.Length > int.MaxValue)
throw new ArgumentException("Serialized object is larger than can fit into
byte array");
byte[] buffer = new Byte[s.Length];
s.Seek(0, SeekOrigin.Begin);
s.Read(buffer, 0, (int)s.Length);
s.Close();
return buffer;
}
--
BLOB is saved into the file with the right size, but most of the characters
are '?'(because
dt.Rows[0]["ColumnBLOB"] is string?)
=====================
I'm sorry for bad english.
Sample code will be appreciated

Thanks.