using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
myDatabaseConnection.Open();
using (SqlCommand SqlCommand = new SqlCommand("Select Photo from Employee where EmpID LIKE '%' + @EmpID + '%' ", myDatabaseConnection))
{
SqlCommand.Parameters.AddWithValue("@EmpID", textBox1.Text);
var DS = new DataSet();
var adapter = new SqlDataAdapter(SqlCommand);
adapter.Fill(DS, "Images");
var imagesTable = DS.Tables["Images"];
var imagesRows = imagesTable.Rows;
var count = imagesRows.Count;
if (count <= 0) return;
var imageColumnValue =
imagesRows[count - 1]["Image"];
if (imageColumnValue == DBNull.Value)
return;
var data = (Byte[])imageColumnValue;
using (var stream = new MemoryStream(data))
{
pictureBox1.Image = Image.FromStream(stream);
}
}
}
If the image is too large for the picturebox
to fit. What is the code to make the image fit in the picturebox
?
My picturebox
is squared, if the image is rectangular how to it crop and show it in the picturebox like this, the lower part of the picture will be removed.