How to save a bitmap in a DataSet?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a row in a DataTable that contains colums of identifying data and I
need to save a bitmap in that row. (I'm going to write the entire DataSet to
disk as XML to be used by another application)

How do I save a bitmap in the DataTable?

Thx.
Andy Jacobs
 
Hi Andy,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to save a bitmap into your
DataTable column and write it to Xml. If there is any misunderstanding,
please feel free to let me know.

When saving files, we can add a byte array column into the DataTable and
save the file as a byte array. We can open the bitmap files with a
FileStream object and read data into the array. Here is an example:

DataTable dt = new DataTable();
dt.Columns.Add("photo", typeof(byte[]));
dt.Rows.Add(dt.NewRow());

FileStream f = new FileStream(@"d:\a.bmp", FileMode.Open);
byte[] b = new byte[f.Length];
f.Read(b, 0, (int)f.Length);
dt.Rows[0]["photo"] = b;

Then we just add the DataTable to a DataSet and use DataSet.WriteXml()
method to save all these to an Xml file.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top