how to get Image from DataSet
-
hi i have DataSet that contain Image. i need to save this Image to File. i try this: SQL = ItemCode,PIC from ROW; dsView = new DataSet(); adp = new SqlCeDataAdapter(SQL, Conn); adp.Fill(dsView, "ROW"); adp.Dispose(); foreach (DataRow R in dsROW.Tables[0].Rows) { ItemCode = R["ItemCode"].ToString().Trim() ; TEMP = R["PIC"].ToString().Trim(); Image image = R["PIC"] as Image; if(image != null) { MemoryStream ms = new MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] imagedata = ms.ToArray(); } but image Always is null and in TEMP i see System.Byte[] need some help, thanks
-
hi i have DataSet that contain Image. i need to save this Image to File. i try this: SQL = ItemCode,PIC from ROW; dsView = new DataSet(); adp = new SqlCeDataAdapter(SQL, Conn); adp.Fill(dsView, "ROW"); adp.Dispose(); foreach (DataRow R in dsROW.Tables[0].Rows) { ItemCode = R["ItemCode"].ToString().Trim() ; TEMP = R["PIC"].ToString().Trim(); Image image = R["PIC"] as Image; if(image != null) { MemoryStream ms = new MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] imagedata = ms.ToArray(); } but image Always is null and in TEMP i see System.Byte[] need some help, thanks
You need to treat R["PIC"] as a byte array. See this: https://social.msdn.microsoft.com/Forums/en-US/4d25dec3-8ce1-40c3-9234-771317e95a14/get-bytearray-from-datarow?forum=adodotnetdataproviders[^] You need to
byte[] myImage = (byte[]) R["PIC"];
MemoryStream ms = new MemoryStream(myImage);
Bitmap mybmp = new Bitmap(ms);Best, John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
-
You need to treat R["PIC"] as a byte array. See this: https://social.msdn.microsoft.com/Forums/en-US/4d25dec3-8ce1-40c3-9234-771317e95a14/get-bytearray-from-datarow?forum=adodotnetdataproviders[^] You need to
byte[] myImage = (byte[]) R["PIC"];
MemoryStream ms = new MemoryStream(myImage);
Bitmap mybmp = new Bitmap(ms);Best, John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
-
thank for the help ! i try this and i got: InvalidCastException i work on C# Windows-Mobile thanks
That means the field is not a blob (thus, it can't be converted to a byte array). Please check the data type of your "pic" Best, John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!