[DataObjectMethod(DataObjectMethodType.Insert, true)]
[System.Web.Services.WebMethod(TransactionOption = TransactionOption.Supported)]
[AutoComplete]
public int addVehCategoryType(byte[] VEHIMAGE)
{
    SqlParameter[] cmdParm ={

        new SqlParameter("@VEHIMAGE", VEHIMAGE),
    };
    return SQLHelper.ExecuteQueryReturnInt(0, constr, 
        "[VEH_VEHICLECATEGORY_ADDVEHICLECATEGORY]", cmdParm, true);
}

<asp:FileUpload id="fuCategoryVehImage" runat="server" Width="220px" CssClass="input" 
Enabled='<%# Bind("VEHIMAGE") %>'></asp:FileUpload>

I have a web services methods like this, so how would i gonna do inserting images through fileupload extender in my form view?

Yes, I would like to insert the images into my SQL database, thanks

I still cannot insert the images into my database. I have the problem with understanding the conversion of datatype and the saving of the images into folder...can someone help and explain to me thanks

The SQL image datatype is obsolete. Use the SQL binary datatype in the Database table; which is essentially a byte array. You can also use a SQL text datatype and convert the image bytes into a string:

string imageBytesString = Convert.ToBase64String(VEHIMAGE);

Text datatypes cannot be indexed and are used for large amounts of text.

Edited 3 Years Ago by Maligui

I have found that the databinding for fileupload does not works as the fields of 'visible' and 'boolean' are in boolean datatype.

I have search online and found that it required other control like textbox and label to bind the data but code fired to textbox is late so it displayed 'Exception have been thrown by target of invocation'.

I tried using 'e.values' but does not work too.
This is my code behind:
*fvCategory = formview

protected void fvCategory_ItemInserting(object sender, FormViewInsertEventArgs e)
{
    FileUpload imagesUpload = (FileUpload)fvCategory.FindControl("imgUpload");
    TextBox textImages = (TextBox)fvCategory.FindControl("txtImg");

    if (imagesUpload.HasFile)
    {
        textImages.Text = imagesUpload.FileName;
        imagesUpload.SaveAs(Server.MapPath("~//images//" + imagesUpload.FileName));
        e.Values.Add("VEHIMAGE", imagesUpload.FileName);
    }
}

Sources:

<asp:FileUpload id="imgUpload" runat="server" Width="220px" CssClass="input" __designer:wfdid="w23" ></asp:FileUpload>
<asp:TextBox id="txtImg" runat="server" Visible="False" Text='<%# Bind("VEHIMAGE") %>' __designer:wfdid="w84" AutoPostBack="True">

Please give comments and advices, thanks

Edited 3 Years Ago by taekiewzz

This article has been dead for over six months. Start a new discussion instead.