c# - data repeater not showing image -
i need please. have used data repeater display values database, columns display values in text boxes on repeater except image. failing convert byte image here's code save database
private void btnsave_click(object sender, eventargs e) { byte[] imagebt = null; filestream fstream = new filestream(this.txtimgpath.text,filemode.open,fileaccess.read); binaryreader br = new binaryreader(fstream); imagebt = br.readbytes((int)fstream.length); // byte[] pic = stream.toarray(); try { condb.open(); oledbcommand command = new oledbcommand(); command.connection = condb; command.commandtext = "insert abaanacc (ccspn_code,ccfname,cclname,ccmname,ccdob,ccgender,ccschool,caclass,ccvillage,ccsiblings,ccguardian,cccontact,ccimage)" + " values ('" + spn_codetxt.text + "','" + txtfname.text + "','" + lnametxt.text + "','" + mnametxt.text + "','" + dobdtpicker1.text + "','" + gendercombobox.text + "','" + schtxt.text + "','" + classcombobox.text + "','" + villatxt.text + "','" + siblingscombobx.text + "','" + guardiantxt.text + "','" + contacttxt.text + "',@img) "; command.parameters.add(new oledbparameter("@img",imagebt)); //command.parameters.addwithvalue("@img",pic); command.executenonquery(); messagebox.show("record saved"); } catch (exception ex) { messagebox.show("unable save" + ex); } condb.close(); }
then data repeater
private void update_load(object sender, eventargs e) { // todo: line of code loads data 'abaanadataset.abaanacc' table. can move, or remove it, needed. this.abaanacctableadapter.fill(this.abaanadataset.abaanacc); int c = this.abaanadataset.abaanacc.rows.count; if (c > 0) ; { byte[] mydata = new byte[0]; mydata = (byte[])(this.abaanadataset.abaanacc.rows[c-1]["ccimage"]); memorystream stream = new memorystream(mydata); ccimagepicturebox.image = image.fromstream(stream); }
}
make sure you're getting valid image data dataset. should work:
private void form3_load(object sender, eventargs e) { this.productphototableadapter.fill(this.adventureworks2014dataset.productphoto); byte[] mydata = (byte[])this.adventureworks2014dataset.productphoto[100]["largephoto"]; memorystream stream = new memorystream(mydata); picturebox1.image = image.fromstream(stream); }
Comments
Post a Comment