且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

单个执行存储过程将多个文件上载到数据库的***方法是什么

更新时间:2023-01-03 16:00:36

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