Hi guys, I am trying to insert image into the database ... I tried everything to do so ...
But still it displaying the error like:
Cannot implicitly convert type 'System.Drawing.Image' to 'System.Web.UI.WebControls.Image'
The code is like this:
public partial class Image : System.Web.UI.Page
{
tblImage objImage = new tblImage();
private byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert,
System.Drawing.Imaging.ImageFormat formatOfImage)
{
byte[] Ret;
try
{
using (MemoryStream ms = new MemoryStream())
{
imageToConvert.Save(ms, formatOfImage);
Ret = ms.ToArray();
}
}
catch (Exception) { throw; }
return Ret;
}
protected void btnUpload_Click(object sender, EventArgs e)
{
objImage.ImageName = txtName.Text;
if (FileUploadControl.HasFile)
{
try
{
System.Drawing.Image imag = System.Drawing.Image.FromStream
(FileUploadControl.PostedFile.InputStream);
objImage.Image = (imag); // Here It is showing the error like "Cannot implicitly convert type 'System.Drawing.Image'
// to 'System.Web.UI.WebControls.Image'.. How to convert it???
}
catch (Exception ex)
{
Label1.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
objImage.InsertNewUser();
Label1.Text = "Record Successfully inserted into the database";
}