0

我一键插入图像文件和声音文件。我正在为该任务调用两个存储过程。但问题是首先图像被保存在数据库中,然后声音文件被覆盖。声音文件未保存在为其分配的单元格中。

这两个存储过程是:

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

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

当我调试我的 ASP.net 应用程序时,我发现在保存声音文件的同时,InsertImageIntoServiceRequest它也被调用并且声音文件与图像文件重叠。

请提出一些建议。

4

1 回答 1

0

@Saksham我写了3种方法:一种用于插入图像和声音,另一种用于调用这两种方法。

[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); 如果 (i > 0) 返回真;返回假;} 捕捉 { 返回错误;} }

[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, 文件, 声音); 如果 (i > 0) 返回真;返回假;} 捕捉 { 返回错误;} }

这两个方法在这里被调用:

[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; 尝试 { rowsAffected =(int)Adapter.CreateServiceRequest(用户名、电子邮件、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;
    }

返回 rowsAffected = 1;

}
于 2013-07-09T05:19:21.383 回答