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);
lastid = dbo.ExecProc1(claim.Remark, claim.BrMkrdt);
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++;
}
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?