Pages

Tuesday, July 7, 2009

Saving the image in SQL Server

hi,

The following is the sample code to show that how we can save the image in the SQL Server. we have to take the column type as IMAGE, and using the BYTE array we can save the uploaded image.

please check the following code for this.


SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
con.
Open();
byte[] ImgBytes = new byte[flurl.PostedFile.InputStream.Length];
flurl.
PostedFile.InputStream.Read(ImgBytes, 0, ImgBytes.Length);
string qry = "Insert into Table1(ImageData) values(@ImageData)";
SqlCommand cmd
= new SqlCommand(qry, con);
cmd.
Parameters.AddWithValue("@ImageData", ImgBytes);
cmd.
ExecuteNonQuery();
con.
Close();

Happy Coding!!!!!!

Thanks
Anil Kumar Pandey
System Architect
Green Point Technology (India) Ltd.
Mumbai, Maharshtra
INDIA

1 comment:

  1. what is package i need to import for

    flurl(Saving the image in SQL Server Port)

    send me responce to santosh.mca08@gmail.com

    regards
    santosh

    ReplyDelete

Kontera