0

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";
    }
1
Contributor
2
Replies
3
Views
5 Years
Discussion Span
Last Post by geniusvishal
0

How to compare Method objImage.Image(System.Web.UI.WebControls.Image) with imag(System.Drawing.Image)... 'imag' is the picture which i am uploading using fileupload control...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.