Hi here image is getting converted into binary and getting inserted into sqltable .
Now I want the opposite of it i mean i want to retrieve the binary
data and display it as image.
protected void btnupload_Click(object sender, EventArgs e)
{
// set temporary variable for database connection
SqlConnection SqlCon = new SqlConnection("Data Source=localhost;Initial Catalog=ArjunPlastic;Uid=sa;Pwd=vagi0903");
SqlCon.Open();
string SQL = "INSERT INTO pictures (Filename,Picture) VALUES ('flower',@image)";
SqlCommand SqlComm = new SqlCommand(SQL,SqlCon);
SqlParameter parimage= new SqlParameter("@image", SqlDbType.Image);
// convert image file to byte array and pass to sql parameter value
parimage.Value = FileToByteArray("C:\\Documents and Settings\\Administrator\\Desktop\\4014_thumb.jpg");
SqlComm.Parameters.Add(parimage);
SqlComm.ExecuteNonQuery();
}
public byte[] FileToByteArray(string FileName)
{
byte[] Buffer = null;
// Open file for reading
FileStream FileStream = new FileStream(FileName,FileMode.Open,FileAccess.Read);
// attach filestream to binary reader
BinaryReader BinaryReader = new BinaryReader(FileStream);
// get total byte length of the file
long TotalBytes = new FileInfo(FileName).Length;
// read entire file into buffer
Buffer = BinaryReader.ReadBytes((Int32)TotalBytes);
// close file reader
FileStream.Close();
FileStream.Dispose();
BinaryReader.Close();
return Buffer;
}