Retrieving the image from database and displaying in web page in Asp.Net -
i trying store profile picture user uploads in database , retrieve database , display in web page.i have saved image in database don't know how retrieve it.i have tried display when click retrieve button nothing happens.
this code in handler page , instead of retrieving image based on id trying passing name of user on welcome page.
public void processrequest(httpcontext context) { //passing name here if (context.request.querystring["name"] != null) { string csc = configurationmanager.connectionstrings["dbcs"].connectionstring; using (sqlconnection con = new sqlconnection(csc)) { sqlcommand com = new sqlcommand("retrieveimage", con); com.commandtype = commandtype.storedprocedure; //passing name sqlparameter p1 = new sqlparameter("@username", context.request.querystring["name"]); com.parameters.add(p1); con.open(); sqldatareader dr = com.executereader(); dr.read(); context.response.binarywrite((byte[])dr["image"]); dr.close(); con.close(); } } else { context.response.write("no image found"); } } public bool isreusable { { return false; } }
i have created stored procedure accepts username , gives image.stored procedure name "retrieveimage" button click event.on clicking button "retrieveimage" calls handler , passes value "name"which calls stored procedure , displays image
protected void retrieveimage_click(object sender, eventargs e) { string csc = configurationmanager.connectionstrings["dbcs"].connectionstring; using (sqlconnection con = new sqlconnection(csc)) { sqlcommand com = new sqlcommand("retrieveimage", con); com.commandtype = commandtype.storedprocedure; sqlparameter p1 = new sqlparameter("@username", welcomeusername.text); com.parameters.add(p1); con.open(); sqldatareader dr = com.executereader(); imagedisp.imageurl = "~/imagepage.ashx?name=" + welcomeusername.text; con.close(); } }
when run page not getting error when click button nothing happens.i new .net .please help.!! in advance
Comments
Post a Comment