I am trying to insert a file (PDF/JPG/XLS) into an image field in my SQL database. Thus far whatever I do, the file is inserted as a NULL value. The GridViewDataHyperLinkColumn is part of a nested detail table. All other fields update just fine.
If I add the following code - I receive an error where I declare "imageBytes":Index was out of range. Must be non-negative and less than the size of the collection.
<asp:SqlDataSource ID="sqlGetDocs" runat="server" OnInserting="SqlGetDocs_Updating" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>" SelectCommand="spAspGetEnrollDocs" SelectCommandType="StoredProcedure" InsertCommand="spASPinsertClientDocDatabase" InsertCommandType="StoredProcedure"> <SelectParameters> <asp:SessionParameter Name="SSN" SessionField="SSN" Type="String" /> </SelectParameters> <InsertParameters> <asp:ControlParameter ControlID="DropDownList1" Name="Client" PropertyName="SelectedValue" Type="String" /> <asp:Parameter Name="SSN" Type="String" /> <asp:Parameter Name="DocDesc" Type="String" /> <asp:Parameter Name="FileType" Type="String" /> <asp:Parameter Name="ImageFile" dbType="Binary" /> <asp:Parameter Name="Updated" Type="DateTime" /> <asp:Parameter Name="Comments" Type="String" /> <asp:ControlParameter ControlID="lblUserName" Name="UserID" PropertyName="Text" Type="String" /> </InsertParameters> </asp:SqlDataSource>If I add the following code - I receive an error where I declare "imageBytes":
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Protected Function UpdateImageField(ByVal gridEditableItem As GridEditableItem) As Byte() Dim bytes As Byte() = (DirectCast(gridEditableItem.EditManager.GetColumnEditor("ImageFile"), GridBinaryImageColumnEditor)).UploadedFileContent If bytes Is Nothing OrElse bytes.Length = 0 Then bytes = New Byte() {} End If Return bytesEnd FunctionProtected Sub SqlGetDocs_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Dim imageBytes As Byte() = UpdateImageField(TryCast(RadGrid.EditItems(0), GridEditableItem)) e.Command.Parameters("@ImageFile").Value = imageBytesEnd Sub
Could someone tell me what I'm doing wrong?