如何使用ASP.Net和&amp ;;将多个图像上传到SQL Server R2。 C# [英] How to upload multiple images to SQL Server R2 using ASP.Net & C#

查看:40
本文介绍了如何使用ASP.Net和&amp ;;将多个图像上传到SQL Server R2。 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我有SId,SName,Image,City。现在我必须为一条记录上传更多图像,如下所示,



SId SName Image City

------- ------- --------------------------------- -------

1 Raju Image1.jpg Image2.gif,Image3.jpg ......等班加罗尔





谢谢提前。

Dear Friends,

I have SId, SName, Image, City. Now i have to upload more image for one record like following these,

SId SName Image City
------ --------- --------------------------------- -------
1 Raju Image1.jpg Image2.gif, Image3.jpg......etc Bangalore


Thanks in advance.

推荐答案

1.对于您当前的数据库表,不可能只将一个字段的多个值插入同一记录中。



2.您必须使用第二个表(名为Images)来存储与您的第一张表中的记录相关联的图像来优化您的数据库:

- 将您的第一个表更改为包含下一个字段: SId,SName,City

- 使用下一个字段创建名为Images的第二个表: ID(自动编号,PK),SId(整数FK),ImageFileName(varchar),图像(图像)

-创建一个FK链接这两个表通过两个表使用 SId ;



3.有关多个文件上传控件的详细信息,可以阅读下一篇文章:

http: //www.itorian.com/2014/01/single-file-upload-to-multiple-file.html [ ^ ]

http://www.asp.net/ajaxlibrary/ajaxcontroltoolkitsamplesite/ajaxfileupload/ajaxfileupload.aspx [ ^ ]



4。关于将数据保存到SQL表中,首先必须将数据插入到第一个表中==> SId ,然后你应该迭代所有文件并使用<$ c $在 Images 表中插入一个新行c> SId 。如果要一起执行所有这个INSERT命令,可以使用事务。查看详细信息:在ADO.NET中使用事务 [ ^ ]
1.For your current database table, it is not possible to insert multiple value for only one fields into the same record.

2.You have to refine your database by using a second table (named Images) for storing the images associated with the record from your first table:
-change your first table to have the next fields: SId, SName, City
-create a 2nd table named Images with the next fields: ID (Autonumber, PK), SId (integer FK), ImageFileName (varchar), Image (Image)
-create a FK link between these two tables by using SId from both tables;

3.For details about multiple file upload controls you could read the next articles:
http://www.itorian.com/2014/01/single-file-upload-to-multiple-file.html[^]
http://www.asp.net/ajaxlibrary/ajaxcontroltoolkitsamplesite/ajaxfileupload/ajaxfileupload.aspx[^]

4.Regarding the saving the data into the SQL tables, first your have to insert the data into your first table ==> SId, then you should iterate all files and insert a new row in the Images table by using the SId . If you want to execute all this INSERT command together you could use transaction. See details: Using Transactions in ADO.NET[^]


这篇关于如何使用ASP.Net和&amp ;;将多个图像上传到SQL Server R2。 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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