我如何...插入数据库10个图像为一个产品,因为我使用Fileupload和Ajax插入Pic1,Pic2,Pic3 ....... Pic10使用此代码 [英] How Do I...Insert Into Database 10 Images For One Product As I Use Fileupload And Ajax By Insert Pic1,Pic2,Pic3 .......Pic10 Using This Code

查看:99
本文介绍了我如何...插入数据库10个图像为一个产品,因为我使用Fileupload和Ajax插入Pic1,Pic2,Pic3 ....... Pic10使用此代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>AJAX FileUpload</title>

</head>

<body>

    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">

    </asp:ScriptManager>

    <div  align="center">

        <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" AllowedFileTypes="jpg,jpeg,png,gif"



                            MaximumNumberOfFiles="10" OnUploadComplete="File_Upload"



                            Width="500px" />

    </div>

    </form>

</body>

</html>







using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using AjaxControlToolkit;

 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    { 

    }

    protected void File_Upload(object sender, AjaxFileUploadEventArgs e)

    {

        string filename = e.FileName;

        string strDestPath = Server.MapPath("~/Documents/");

        AjaxFileUpload1.SaveAs(@strDestPath + filename);       

    }

}

推荐答案

OnUploadComplete 事件将在每个文件上载完成后触发。您需要做的是在事件触发时将 OnUploadComplete 中的当前文件插入数据库。

检查这篇博客文章 [ ^ ]了解更多信息



- 使用EF和ASP.NET在SQL Server中存储图像 [ ^ ]

- 如何使用C#在Microsoft SQL Server和ASP.NET中存储和检索图像? [ ^ ]

- 使用asp.net在sql server 2008中保存图像 [ ^ ]
OnUploadComplete event will fire after each file upload complete. What you need to do is insert current file in OnUploadComplete to the database when the event fire.
Check this blog post[^] for more information

- Storing Images in SQL Server using EF and ASP.NET[^]
- How to store and retrieve images in Microsoft SQL Server and ASP.NET using C# ?[^]
- Image saving in sql server 2008 with asp.net[^]


这篇关于我如何...插入数据库10个图像为一个产品,因为我使用Fileupload和Ajax插入Pic1,Pic2,Pic3 ....... Pic10使用此代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆