protected void Button1_Click(object sender, EventArgs e)
{
try
{
int len = image.PostedFile.ContentLength;
string path = "C:\\";
string filename = image.PostedFile.FileName;
image.SaveAs(path + filename);
FileInfo imageInfo = new FileInfo(path + filename);
byte[] content = new byte[len];
image.PostedFile.InputStream.Read(content, 0, len);
SqlConnection objConn = new SqlConnection();
SqlCommand objCom = new SqlCommand();
objConn = new SqlConnection("");
objCom = new SqlCommand("UPDATE tbl SET Afbeeldingpad = @Picture WHERE InstellingID = 1", objConn);
SqlParameter pictureParameter = new SqlParameter("@Picture", SqlDbType.Image, len);
pictureParameter.Value = content;
objCom.Parameters.Add(pictureParameter);
objConn.Open();
objCom.ExecuteNonQuery();
objConn.Close();
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
try
{
SqlConnection objConn = new SqlConnection();
SqlCommand objCom = new SqlCommand();
objConn = new SqlConnection("");
objCom = new SqlCommand("SELECT afbeeldingpad FROM tbl WHERE InstellingID = 1", objConn);
objConn.Open();
SqlDataReader SR = objCom.ExecuteReader(CommandBehavior.CloseConnection);
while (SR.Read())
{
byte[] content = (byte[])SR["Afbeeldingpad"];
Response.ContentType = "image/jpg";
Response.BinaryWrite(content);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
Reacties
Een reactie posten