Posts

Showing posts from September, 2017

Return Image from Generic Handler that stored in Sql Server Database Varbinary Database Asp.Net C#

<%@ WebHandler Language="C#" Class="GalleryImg" %> using System; using System.Web; using System.Data; using System.Data.SqlClient; using System.IO; using System.Configuration; public class GalleryImg : IHttpHandler {     public void ProcessRequest(HttpContext context)     {         int id;         if (context.Request.QueryString["id"] != null || context.Request.QueryString["id"] != "")         {             id = Convert.ToInt32(context.Request.QueryString["id"]);             context.Response.ContentType = "image/jpeg";             Stream strm = DisplayImage(id);             byte[] buffer = new byte[2048];     ...

Save Image to SQL Server using varbinary,varbinary(Max) datatype

cn.Open(); SqlCommand cmd = new SqlCommand("Usp_InsertEvent", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("Event_Name",TxtTitle.Text); cmd.Parameters.AddWithValue("Event_Description",TxtDescription.Text); Byte[] image1 = null; if (FileUpload1.HasFile && FileUpload1.PostedFile != null) {     HttpPostedFile File = FileUpload1.PostedFile;     image1 = new Byte[File.ContentLength];     File.InputStream.Read(image1, 0, File.ContentLength);     cmd.Parameters.AddWithValue("Image", image1); } else {     cmd.Parameters.Add("Photo1", SqlDbType.VarBinary).Value=DBNull.Value; } int x=cmd.ExecuteNonQuery(); cn.Close();