ورود

View Full Version : مشکل در convert عکس های binary از دیتابیس به اپلیکیشن



benyaminP1noQ
دوشنبه 19 خرداد 1393, 14:42 عصر
سلام.
دوستان من حدود 150 تا عکس رو به صورت باینری در دیتابیس ذخیره کردم.
حالا این عکس ها به صورت شرطی از دیتابیس خونده میشه و در اپلیکیشن نمایش داده میشه ( در یک شرط ممکنه که 20 تا عکس نمایش داده بشه )
اما مشکلی که من دارم اینه که فقط یک عکس رو به من نشون میده .
نکته ی اصلی اینه که نباید از gridview و eval() استفاده بشه.

دوستان خواهش میکنم اگه کسی بلده کمک کنه.
اینم syntax ایه که من براش نوشتم
داخل generic handler (ashx ) :


public class Hotel : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
Int32 my_Id;
if (context.Request.QueryString["getID"] != null)
{
my_Id = Convert.ToInt32(context.Request.QueryString["getID"]);
context.Response.ContentType = "Images/HotelPic";
Stream strm = ShowEmpImage(my_Id);
byte[] buffer = new byte[4096];
int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 4096);
}
}
}

public Stream ShowEmpImage(int my_Id)
{
SqlConnection connection = new SqlConnection("Data Source=Samsung-Pc;Initial Catalog=Reservation;User ID=sa;Password=12");

//SqlCommand cmd = new SqlCommand("select HotelPictures from Hotels WHERE Id = @ID", connection);

//cmd.Parameters.AddWithValue("@ID", my_Id);


SqlCommand cmd = new SqlCommand("USP_HotelPic_select", connection);
cmd.Parameters.AddWithValue("@MemberId", SqlDbType.Int).SqlValue = my_Id;
cmd.CommandType = CommandType.StoredProcedure;
connection.Open();
object img = cmd.ExecuteScalar();
return new MemoryStream((byte[])img);

}

public bool IsReusable
{
get
{
return false;
}
}
}


و اینم کد c# :

Image1.ImageUrl = "~/Images.ashx?getID=" + ID +"";

اون متغیر ID مقدار فیلد id داخل دیتابیسم رو داخلش میریزه اما بازم مشکل دارم