我只需点击一下按钮即可插入图像文件和声音文件。我正在为该任务调用两个存储过程。但问题是首先将图像保存在数据库中,然后声音文件覆盖它。声音文件未保存在为其分配的单元格中。
这两个存储过程是:
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
也被调用,声音文件与图像文件重叠。
请提出建议。
答案 0 :(得分:0)
@Saksham 我写了3个方法:一个用于插入图像和声音,另一个用于调用这两种方法。
[System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Insert,false)] public bool InsertImage(int ServiceRequestID,string Filename,byte [] image) { 尝试 { int i = Adapter.InsertImageIntoServiceRequest(ServiceRequestID,Filename,image); if(i> 0) 返回true; 返回false; } 抓住 { 返回false; } }
和
[System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Insert,false)] public bool InsertSound(int ServiceRequestID,string Filename,byte [] sound) { 尝试 { string file = Filename.Replace('','_'); int i = Adapter.InsertImageIntoServiceRequest(ServiceRequestID,file,sound); if(i> 0) 返回true; 返回false; } 抓住 { 返回false; } }
这两种方法在这里被称为:
[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(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;
}