Kevin Fralick

Kevin Fralick

  • NA
  • 21
  • 11.3k

Query image from database, and save to local?

Jan 25 2012 11:55 AM
Hi all,

I'm querying an email address and an image field.  I need to save the image field to my local where the name is in the form of
<email address>.jpeg.

I think some conversion is necessary through Bitmap.  I've never done this before and am having problems with it.  If you could tell me what I'm doing wrong, I would greatly appreciate it.

SqlCommand query = new SqlCommand("SELECT a.email, b.image01 from empmast a, picture b where a.perno = b.perno");

query.Connection = con;
SqlDataAdapter mysqldataadapter = new SqlDataAdapter();
mysqldataadapter.SelectCommand = query;

DataSet mydataset = new DataSet();

con.Open();
mysqldataadapter.Fill(mydataset, "email"); 
DataTable mydataTable = mydataset.Tables["email"];

foreach (DataRow DR in mydataTable.Rows)
{

//Bitmap bmp1 = CreateBitmapImage(DR[1].ToString());

Bitmap bmp1 = new Bitmap(DR[1]);
bmp1.Save("c:\\image\\" + DR[0] + ".Jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
}

Answers (1)