c# 4.0 - retrieve image from MS Access -


i want retrieve image ms access database showing in picturebox code code this:

private void button1_click(object sender, eventargs e)     {         oledbconnection myconnection = new oledbconnection(configurationmanager.connectionstrings["connectionstring"].connectionstring);          myconnection.open();         oledbcommand cmd = new oledbcommand("select * [images] id=1", myconnection);         oledbdataadapter da = new oledbdataadapter(cmd);         datatable dt = new datatable();         da.fill(dt);          if (dt.rows.count > 0)         {             if (dt.rows[0]["aimage"] != dbnull.value)             {                 picturebox.image = bytearraytoimage((byte[])dt.rows[0]["aimage"]);             }         }         myconnection.close();         }      bitmap bytearraytoimage(byte[] b)     {         memorystream ms = new memorystream();         byte[] pdata = b;         ms.write(pdata, 0, convert.toint32(pdata.length));         bitmap bm = new bitmap(ms, false);         ms.dispose();         return bm;     } 

but there error like:"parameter not valid." bitmap bm = new bitmap(ms, false); don't know why?

from msdn documentation bitmap constructor: bitmap(stream, boolean)

a system.argumentexception thrown if:

stream not contain image data or nothing.

-or-

stream contains png image file single dimension greater 65,535 pixels.

and

remarks

you must keep stream open lifetime of bitmap.

due limitation of gdi+ decoder, system.argumentexception thrown if construct bitmap .png image file single dimension greater 65,535 pixels.

have checked properties of image retrieving access database see if describes error situation?


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -