单个执行存储过程将多个文件上载到数据库的最佳方法是什么 [英] What will be the best approach for uploading multiple files to database with single execution of stored procedure

查看:63
本文介绍了单个执行存储过程将多个文件上载到数据库的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在webform上有5个FileUpload控件..我有两个sql server表...



 Tbl_ClaimDetails 
SrNo |备注| BrMkrdt


Tbl_ClaimImages
SrNo | Img | Id | ImgName







第一个文件上传控件是强制性的。例如,如果用户选择要上载的3个文件,则第一个图像文件用于通过存储过程将数据插入Tbl_ClaimDetails(Tbl_ClaimDetails中的SrNo是标识)我将使用SCOPE_IDENTITY()返回最后一个srno。我在变量lastid中存储了

  SCOPE_IDENTITY ()





现在我正在使用另一个存储过程在第一张图像

 

以及lastid的Tbl_ClaimImages中插入数据..

  if (file1.ContentLength >   0 &&(u1!=  null  || u1!=  0 ))
{
Stream fs = file1.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte [] bytes = br.ReadBytes(( Int32 )fs.Length);

// 存储过程在tbl_claimdetails中插入数据并返回SCOPE_IDENTITY()
lastid = dbo.ExecProc1(claim.Remark,claim.BrMkrdt);
// 另一个存储过程在tbl_ClaimImages中插入数据
dbo.insert(bytes ,lastid,file1.FileName);
count ++;
}

if (file2.ContentLength > 0 &&(u1!= null || u1!= 0 ))
{
Stream fs = file2.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte [] bytes = br.ReadBytes(( Int32 )fs.Length);
dbo.insert(bytes,lastid,file1.FileName);
count ++;
} // 依此类推至file5









这种方法运行正常。我没有任何错误或问题,但我想知道是否有比这更好的方法?正如您所看到的,我正在执行两个不同的存储过程,用于在给定的表中插入值。在Tbl_ClaimDetails中插入值的存储过程在开始时仅执行一次,然后我再次执行另一个存储过程以根据用户上载的图像数量在Tbl_ClaimImages中插入值。是否可以在一次执行中使用一个存储过程完成所有这些操作?或者有更好的方法吗?

解决方案

http://www.aspdotnet-suresh.com/2012/12/jquery-uploading-multiple-files-in.html

http://www.aspdotnet-suresh.com/2012/12/jquery-uploading-multiple-files-in.html

参考此链接会有所帮助

I have 5 FileUpload controls on a webform.. I have two sql server tables...

Tbl_ClaimDetails
SrNo | Remark | BrMkrdt


Tbl_ClaimImages
SrNo | Img | Id | ImgName




The first file upload control is compulsory. For instance if a user selects 3 files to be uploaded then the first image file is used to insert data into Tbl_ClaimDetails through stored procedure (SrNo in Tbl_ClaimDetails is identity) i am returning the last srno using SCOPE_IDENTITY(). I am storing this

SCOPE_IDENTITY()

value in a variable lastid

Now i am using another stored procedure to insert data in Tbl_ClaimImages of this first image

along with lastid..

if (file1.ContentLength > 0 && (u1 != null || u1 != 0))
{
                Stream fs = file1.InputStream;
                BinaryReader br = new BinaryReader(fs);
                Byte[] bytes = br.ReadBytes((Int32)fs.Length);

//store procedure inserts data in tbl_claimdetails and return SCOPE_IDENTITY()
                lastid = dbo.ExecProc1(claim.Remark,  claim.BrMkrdt);
//another stored procedure inserts data in tbl_ClaimImages
                dbo.insert(bytes, lastid, file1.FileName);    
             count++;
}

if (file2.ContentLength > 0 && (u1 != null || u1 != 0))
{
                Stream fs = file2.InputStream;
                BinaryReader br = new BinaryReader(fs);
                Byte[] bytes = br.ReadBytes((Int32)fs.Length);                
                dbo.insert(bytes, lastid, file1.FileName);    
             count++;
}// and so on till file5





This approach is working fine. I do not have any errors or problem BUT i want to know if there is a better approach than this? As you can see i am executing two different stored procedures for inserting values in the given to tables. The stored procedure which inserts values in Tbl_ClaimDetails gets executed just once at the beginning and then i am executing another stored procedure again and again to insert values in Tbl_ClaimImages depending on number of images user is uploading. Is it possible all this can be done using one single stored procedure in one single execution? Or is there better approach?

解决方案

http://www.aspdotnet-suresh.com/2012/12/jquery-uploading-multiple-files-in.html
http://www.aspdotnet-suresh.com/2012/12/jquery-uploading-multiple-files-in.html
refer this links it would be helpful


这篇关于单个执行存储过程将多个文件上载到数据库的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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