public void InsertImage(string photoFilePath,string connectionString)
{
byte[] photo = LoadImage(photoFilePath);
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand( "INSERT INTO tblPhotos(Photo) " + "Values(@Photo)", connection);
command.Parameters.Add("@Photo", SqlDbType.Image, photo.Length).Value = photo;
connection.Open();
command.ExecuteNonQuery();
}
}
public static byte[] LoadImage(string filePath)
{
FileStream stream = new FileStream(
filePath, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(stream);
byte[] photo = reader.ReadBytes((int)stream.Length);
reader.Close();
stream.Close();
return photo;
}
Thanks & Regards
Solimon Joseph
Shanky11, if this helps please login to Mark As Answer. | Alert Moderator