0

I am inserting an image file and a sound file in one button click. I am calling two stored procedures for the task. But the problem is first the image is getting saved in the database and then the sound file is overwriting it. The sound file is not getting saved in the cell allocated for it.

The two stored procedures are:

ALTER PROCEDURE [dbo].[InsertImageIntoServiceRequest] 
(@ServiceRequestID int,
@FileName nvarchar(150),
@Image varbinary(max))
AS
BEGIN
update ServiceRequest
set ImageFilename=@FileName, [Image]=@Image
where ID=@ServiceRequestID
END

and

ALTER PROCEDURE [dbo].[InsertSoundIntoServiceRequest] 
(@ServiceRequestID int,
@FileName nvarchar(150),
@Sound varbinary(max))
AS
BEGIN
update ServiceRequest
set SoundFilename=@FileName, Sound=@Sound
where ID=@ServiceRequestID
END

When I debugged my ASP.net application I found that while saving the sound file the InsertImageIntoServiceRequest is also getting called and the sound file is overlapping the image file.

Please suggest something.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Chandrima
  • 1
  • 1

1 Answers1

0

@Saksham I have written 3 methods: one for each for inserting image and sound and one for calling these two methods.

[System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Insert, false)] public bool InsertImage(int ServiceRequestID, string Filename, byte[] image) { try { int i = Adapter.InsertImageIntoServiceRequest(ServiceRequestID, Filename, image); if (i > 0) return true; return false; } catch { return false; } }

and

[System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Insert, false)] public bool InsertSound(int ServiceRequestID, string Filename, byte[] sound) { try { string file = Filename.Replace(' ', '_'); int i = Adapter.InsertImageIntoServiceRequest(ServiceRequestID, file, sound); if (i > 0) return true; return false; } catch { return false; } }

These two methods are called here:

[System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Insert, true)] public int CreateServiceRequest(string Username,string EMail,string CenterIPIN,int ServiceType,int ServiceStatus,string Notes, DataTable image, DataTable sound) { int rowsAffected; try { rowsAffected =(int)Adapter.CreateServiceRequest(Username, EMail, CenterIPIN, ServiceType, ServiceStatus, Notes);

        ServiceRequestBLL srb = new ServiceRequestBLL();
        if (image != null)
        {
            foreach (DataRow dr in image.Rows)
            {
                srb.InsertImage(rowsAffected, dr["Filename"].ToString(), (byte[])dr["Image"]);
            }
        }
        if (sound != null)
        {
            foreach (DataRow dr1 in sound.Rows)
            {
                try
                {
                    srb.InsertSound(rowsAffected, dr1["Filename"].ToString(), (byte[])dr1["Sound"]);
                }
                catch (Exception ex)
                {
                    rowsAffected = 0;
                }
            }
        }

    }
    catch
    {
        rowsAffected = 0;
    }

return rowsAffected = 1;

}
Chandrima
  • 1
  • 1