Binary data displayed instead of image in c# and mysql -
public void processrequest(httpcontext context) { mysqlconnection con = new mysqlconnection(configurationmanager.connectionstrings["constring"].connectionstring.tostring()); // create sql command int adid= int.parse(context.request.querystring["adid"]); int imgid = int.parse(context.request.querystring["imgid"]); mysqlcommand cmd = new mysqlcommand(); //cmd.commandtext = "select i.image_id, i.image_name, i.image_byteimage, i.image_adid images i,postadverties p i.image_adid =@id"; cmd.commandtext = "select image_id,image_byteimage images image_adid="+ adid + " , image_id="+ imgid; cmd.commandtype = system.data.commandtype.text; cmd.connection = con; //mysqlparameter adid = new mysqlparameter("@id", mysqldbtype.int32); //mysqlparameter imgid = new mysqlparameter("@imgid", mysqldbtype.int32); //adid.value = //imgid.value = //cmd.parameters.add(adid); //cmd.parameters.add(imgid); con.open(); mysqldatareader dreader = cmd.executereader(); if (dreader.read()) { byte[] binaryimg = (byte[])dreader["image_byteimage"]; string base64string = "data:image/jpeg;base64," + convert.tobase64string(binaryimg); context.response.write(base64string); context.response.flush(); context.response.end(); } dreader.close(); con.close(); }
click here see result when trying display images stored in database above result displayed instead of image.no clue why issue coming.is there problem while converting or else.in page works , on pages not.
Comments
Post a Comment