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();

Comments

Popular posts from this blog

Uploading Image to Sql Server Image Datatype in asp.net using fileupload Control

Get Running Sum of Query SQL Query