The client and JS code don't have access to the database (hopefully that's obvious). So you need to provide a server script to load an image from the database and return it as a HTTP 'file', and then have the JavaScript load that URL.
I've not actually done this in ASPX so pseudocode only, but what you need to do is something like
int id = Page.QueryVars["id"];
DataTable dt = query("select mimetype, image from images where imageid="+id);
switch(dt.RowCount){
case 1:
Response.MimeType = (string)dt[0]["mimetype"];
Response.Write((byte[])dt[0]["image"]);
break;
case 0:
Response.Code = 404;
break;
default:
Response.Code = 500;
Response.Write("Unexpected duplicate image id "+id);
break;
}
Then you would call it by retrieving getimage.aspx?id=5.
Hopefully someone who's actually done this in ASPX can fill this out a bit more. (I've done something similar in PHP where the algorithm is the same but obviously the code is completely different.)