I have uploaded an Image into database through C# application. Here is my code.
FileStream fs1 = new FileStream(toolStripLableClientSelectedImage.Text, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] image = new byte[fs1.Length];
fs1.Read(image, 0, Convert.ToInt32(fs1.Length));
fs1.Close();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "INSERT INTO tblClientDetails ([clFname], [clName], [clAddress], [clCity], [clState], [clPhone1], [clPhone2], [clEmail1], [clEmail2], [clProfession], [clPhoto]) VALUES ('" + txtClFirstName.Text + "', '" + txtClLastName.Text + "', '" + txtClAddress.Text + "', '" + cmbClCity.Text + "','" + cmbClState.Text + "' ,'" + txtClPhone1.Text + "' ,'" + txtClPhone2.Text + "' ,'" + txtClMail1.Text + "' ,'" + txtClMail2.Text + "' ,'" + cmbClProfession.Text + "', @Pic)";
try
{
SqlParameter prm = new SqlParameter("@Pic", SqlDbType.VarBinary, image.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, image);
cmd.Parameters.Add(prm);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Data Inserted Succcessfully");
}
catch (Exception ab)
{
//MessageBox.Show("Following Error Occured. May Be Unable To Upload Image ", ab.Message);
MessageBox.Show(ab.Message, "Error");
con.Close();
}
This is the code I am using for uploading Image into database.
Please tell me how to write a code for downloading image from this database/filestream.