c# - Extract images through database -
i working on extracting images database(sql server 2008) im using wpf application , using grid_loaded event load pages. examples have found using combo box select id of image , displaying it. not want use combo box.
i have few lines of code have worked on , found on internet, appreciated if helps me!
private void loadimages() { try { string connstr = @"server=ctgpjlpc21\sqlexpress;database=testing;trusted_connection=true;"; using (sqlconnection conn = new sqlconnection(connstr)) { conn.open(); using (sqldataadapter adapter = new sqldataadapter("select * test_table", conn)) { dset = new dataset(); adapter.fill(dset); } datatable dt = dset.tables[0]; foreach (datarow row in dt.rows) { if (dset.tables[0].rows.count == 1) { byte[] data = (byte[])dset.tables[0].rows[0][0]; memorystream strm = new memorystream(); strm.write(data, 0, data.length); strm.position = 0; system.drawing.image img = system.drawing.image.fromstream(strm); bitmapimage bi = new bitmapimage(); bi.begininit(); memorystream ms = new memorystream(); img.save(ms, system.drawing.imaging.imageformat.bmp); ms.seek(0, seekorigin.begin); bi.streamsource = ms; bi.endinit(); myimg.source = bi; } } } } catch (exception ex) { messagebox.show(ex.message); } }
long buffersize = datareader.isdbnull(1) ? 0 : datareader.getint64(1); if (buffersize > 0) { j.picturecontent = new byte[buffersize]; buffersize = datareader.getbytes(1, 0, j.picturecontent, 0, convert.toint32(buffersize)); }
j class instance , j.picturecontent byte[].
Comments
Post a Comment