how to check the database if I insert a picture.
-
mercredi 1 février 2012 00:04
how to check the database column with Slika2 if I insert a picture.
- Déplacé Esther FanMicrosoft Employee vendredi 22 juin 2012 15:12 (From:Modeling and Tools)
Toutes les réponses
-
mercredi 1 février 2012 00:07
To datebse insight picture of usehow to check the database column with Slika2 if I insert a picture.
<% @ WebHandler Language = "C #" Class = "Handler"%>
using System;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
public class Handler: IHttpHandler {
public void ProcessRequest (HttpContext context)
{
SqlConnection con = new SqlConnection (@ "Data Source = RU-PC \ SQLEXPRESS; Initial Catalog = Proizvodi; Integrated Security = True");
/ / Create SQL Command
SqlCommand cmd = new SqlCommand ();
cmd.CommandText = "SELECT Slika5 FROM Proizvodi" +
"WHERE Pro_ID = @ ID";
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
SqlParameter ImageID = new SqlParameter
("@ ID", System.Data.SqlDbType.Int);
ImageID.Value = context.Request.QueryString ["ID"];;
cmd.Parameters.Add (ImageID);
con.Open ();
SqlDataReader dReader = cmd.ExecuteReader ();
dReader.Read ();
context.Response.BinaryWrite ((byte []) dReader ["Slika5"]);
dReader.Close ();
con.Close ();
}
public bool IsReusable
{
get
{
return false;
}
}
} -
jeudi 2 février 2012 09:19
Add an picturebox control in your application and use the below code
using (MemoryStream ms = new MemoryStream((byte[])dReader["Slika5"])) { ms.Position = 0; ms.Seek(0, SeekOrigin.Begin); pictureBox1.Image = System.Drawing.Image.FromStream(ms); ms.Flush(); ms.Close(); }

