我有三种状态的 FormView:ItemTemplate、EditItemTemplate 和 InsertItemTemplate。在 ItemTemaplate 中,我可以通过外部方式从数据库下载文件:
<asp:LinkButton runat="server" OnCommand="GetBenefitPdf" CommandArgument='<%# Eval("benefit_id") %>' Text="Get PDF" />
和:
protected void GetBenefitPdf(object sender, CommandEventArgs e)
{
int benefit_id = int.Parse(e.CommandArgument.ToString());
Response.Redirect("GetPdf.aspx?id=" + benefit_id + "&page=ManageBenefits.aspx");
}
但是我还需要在InsertItemTemplate和EditItemTemplate中上传一个文件(附件)。在上述两个中,我都做了:
<asp:FileUpload ID="filedata" runat="server" />
但是 SQL 命令(给出了参数)是个例外:
字符串或二进制数据将被截断。该语句已终止。
我该如何处理?
编辑:给出了 SQL:
<asp:SqlDataSource ID="SqlDataSourceManageBenefits" runat="server" ConnectionString="<%$ ConnectionStrings:validConnectionString %>"
SelectCommand="SELECT [min_buyers], [active], [benefit_id], [name], [description], [price], [avail_pcs], [type], [months], [link], [family], [start_date], [end_date], [months_cancel], [price_month], [price_full], [payroll], [payroll_add], [payroll_sub], [price_all], [labor_id], [filedata] FROM [benefits]"
FilterExpression=" type='{0}' " ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM [benefits] WHERE [benefit_id] = @original_benefit_id AND (([min_buyers] = @original_min_buyers) OR ([min_buyers] IS NULL AND @original_min_buyers IS NULL)) AND [active] = @original_active AND (([name] = @original_name) OR ([name] IS NULL AND @original_name IS NULL)) AND (([description] = @original_description) OR ([description] IS NULL AND @original_description IS NULL)) AND (([price] = @original_price) OR ([price] IS NULL AND @original_price IS NULL)) AND (([avail_pcs] = @original_avail_pcs) OR ([avail_pcs] IS NULL AND @original_avail_pcs IS NULL)) AND (([type] = @original_type) OR ([type] IS NULL AND @original_type IS NULL)) AND (([months] = @original_months) OR ([months] IS NULL AND @original_months IS NULL)) AND (([link] = @original_link) OR ([link] IS NULL AND @original_link IS NULL)) AND (([family] = @original_family) OR ([family] IS NULL AND @original_family IS NULL)) AND (([start_date] = @original_start_date) OR ([start_date] IS NULL AND @original_start_date IS NULL)) AND (([end_date] = @original_end_date) OR ([end_date] IS NULL AND @original_end_date IS NULL)) AND (([months_cancel] = @original_months_cancel) OR ([months_cancel] IS NULL AND @original_months_cancel IS NULL)) AND (([price_month] = @original_price_month) OR ([price_month] IS NULL AND @original_price_month IS NULL)) AND (([price_full] = @original_price_full) OR ([price_full] IS NULL AND @original_price_full IS NULL)) AND (([payroll] = @original_payroll) OR ([payroll] IS NULL AND @original_payroll IS NULL)) AND (([payroll_add] = @original_payroll_add) OR ([payroll_add] IS NULL AND @original_payroll_add IS NULL)) AND (([payroll_sub] = @original_payroll_sub) OR ([payroll_sub] IS NULL AND @original_payroll_sub IS NULL)) AND (([price_all] = @original_price_all) OR ([price_all] IS NULL AND @original_price_all IS NULL)) AND (([labor_id] = @original_labor_id) OR ([labor_id] IS NULL AND @original_labor_id IS NULL)) AND (([filedata] = @original_filedata) OR ([filedata] IS NULL AND @original_filedata IS NULL))" InsertCommand="INSERT INTO [benefits] ([min_buyers], [active], [name], [description], [price], [avail_pcs], [type], [months], [link], [family], [start_date], [end_date], [months_cancel], [price_month], [price_full], [payroll], [payroll_add], [payroll_sub], [price_all]), [labor_id], [filedata] VALUES (@min_buyers, @active, @name, @description, @price, @avail_pcs, @type, @months, @link, @family, @start_date, @end_date, @months_cancel, @price_month, @price_full, @payroll, @payroll_add, @payroll_sub, @price_all, @labor_id, @filedata)" OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [benefits] SET [min_buyers] = @min_buyers, [active] = @active, [name] = @name, [description] = @description, [price] = @price, [avail_pcs] = @avail_pcs, [type] = @type, [months] = @months, [link] = @link, [family] = @family, [start_date] = @start_date, [end_date] = @end_date, [months_cancel] = @months_cancel, [price_month] = @price_month, [price_full] = @price_full, [payroll] = @payroll, [payroll_add] = @payroll_add, [payroll_sub] = @payroll_sub, [price_all] = @price_all, [labor_id] = @labor_id, [filedata] = @filedata WHERE [benefit_id] = @original_benefit_id AND (([min_buyers] = @original_min_buyers) OR ([min_buyers] IS NULL AND @original_min_buyers IS NULL)) AND [active] = @original_active AND (([name] = @original_name) OR ([name] IS NULL AND @original_name IS NULL)) AND (([description] = @original_description) OR ([description] IS NULL AND @original_description IS NULL)) AND (([price] = @original_price) OR ([price] IS NULL AND @original_price IS NULL)) AND (([avail_pcs] = @original_avail_pcs) OR ([avail_pcs] IS NULL AND @original_avail_pcs IS NULL)) AND (([type] = @original_type) OR ([type] IS NULL AND @original_type IS NULL)) AND (([months] = @original_months) OR ([months] IS NULL AND @original_months IS NULL)) AND (([link] = @original_link) OR ([link] IS NULL AND @original_link IS NULL)) AND (([family] = @original_family) OR ([family] IS NULL AND @original_family IS NULL)) AND (([start_date] = @original_start_date) OR ([start_date] IS NULL AND @original_start_date IS NULL)) AND (([end_date] = @original_end_date) OR ([end_date] IS NULL AND @original_end_date IS NULL)) AND (([months_cancel] = @original_months_cancel) OR ([months_cancel] IS NULL AND @original_months_cancel IS NULL)) AND (([price_month] = @original_price_month) OR ([price_month] IS NULL AND @original_price_month IS NULL)) AND (([price_full] = @original_price_full) OR ([price_full] IS NULL AND @original_price_full IS NULL)) AND (([payroll] = @original_payroll) OR ([payroll] IS NULL AND @original_payroll IS NULL)) AND (([payroll_add] = @original_payroll_add) OR ([payroll_add] IS NULL AND @original_payroll_add IS NULL)) AND (([payroll_sub] = @original_payroll_sub) OR ([payroll_sub] IS NULL AND @original_payroll_sub IS NULL)) AND (([price_all] = @original_price_all) OR ([price_all] IS NULL AND @original_price_all IS NULL)) AND (([labor_id] = @original_labor_id) OR ([labor_id] IS NULL AND @original_labor_id IS NULL)) AND (([filedata] = @original_filedata) OR ([filedata] IS NULL AND @original_filedata IS NULL))">
还有参数:
<asp:Parameter Name="original_filedata" Type="Byte" />
<asp:Parameter Name="filedata" Type="Byte" />