使用if-else语句在数据库中不更新相同的映像 [英] Same image does not update in database using if-else statement

查看:65
本文介绍了使用if-else语句在数据库中不更新相同的映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ALTER   PROCEDURE  [dbo]。[SP_Updatemstproduct] 

@ poProductId int
@ caCategoryId int
@ poProductName varchar 200 ),
@ poDescription varchar 300 ),
@ poSmallImage varchar 200 ),
@ poIsActive varchar 1 ),
@poOrder int
- @ poCreatedDate datetime


AS
BEGIN
IF @ poSmallImage = ' '
开始
更新 [mst_product]
SET
[caCategoryId] = @ caCategoryId
[poProductName] = @ poProductName
[poDescription] = @ poDescription
[poSmallImage] = @ poSmallImage
[poIsActive] = @ poIsActive
[poOrder] = @ poOrder
- [p oCreatedDate] = @poCreatedDate
WHERE poProductId = @ poProductId
END
else
开始
更新 [mst_product]
SET
[caCategoryId] = @ caCategoryId
[poProductName] = @ poProductName
[poDescription] = @ poDescription
- [poSmallImage] = @poSmallImage,
[poIsActive] = @ poIsActive
[poOrder] = @ poOrder
- [poCreatedDate] = @poCreatedDate
WHERE poProductId = @ poProductId
end
end





我试过了什么:



其实我试过数据库是同一图片不在数据库中更新

我在更新中使用此代码

 if(fileImage.PostedFile!= null)
{
string FileName = Path.GetFileName(fileImage.PostedFile.FileName);
fileImage.SaveAs(Server.MapPath(Images /+ FileName));



此字段用于更新SP

 cmd2.Parameters.AddWithValue(@ poSmallImage,Images /+ FileName); 

解决方案

我认为你的问题在于:

 IF(@poSmallImage ='')

嗯...... IF永远不会成功,所以UPDATE代码永远不会执行。

你总是传递一个非空的字符串SP(它始终以文本Images开头) /)所以IF总是无法匹配一个空字符串。

也许你想要这个:

 IF(@poSmallImage!='' )


ALTER PROCEDURE  [dbo].[SP_Updatemstproduct]
(
	@poProductId int ,
	@caCategoryId int,
	@poProductName varchar(200),
	@poDescription varchar(300),
	@poSmallImage varchar(200),
	@poIsActive varchar(1),
    @poOrder int
	--@poCreatedDate datetime
)

AS
BEGIN
     IF (@poSmallImage = '')
begin
UPDATE [mst_product]
   SET 
      [caCategoryId] = @caCategoryId, 
      [poProductName] = @poProductName, 
      [poDescription] = @poDescription, 
      [poSmallImage] = @poSmallImage, 
      [poIsActive] = @poIsActive,
      [poOrder]=@poOrder
   --[poCreatedDate] = @poCreatedDate
 WHERE poProductId=@poProductId
END
else
begin
UPDATE [mst_product]
   SET 
      [caCategoryId] = @caCategoryId, 
      [poProductName] = @poProductName, 
      [poDescription] = @poDescription, 
      --[poSmallImage] = @poSmallImage, 
      [poIsActive] = @poIsActive,
      [poOrder]=@poOrder
   --[poCreatedDate] = @poCreatedDate
 WHERE poProductId=@poProductId
end 
end



What I have tried:

actually I m tried the database is same image does not update in database
I used this code for in update

if (fileImage.PostedFile != null)
            {
                string FileName = Path.GetFileName(fileImage.PostedFile.FileName);
                fileImage.SaveAs(Server.MapPath("Images/" + FileName));


and this field is use to update SP

cmd2.Parameters.AddWithValue("@poSmallImage", "Images/" + FileName);

解决方案

I think your problem is in the line:

IF (@poSmallImage = '')


Well...the IF will never succeed, so the UPDATE code will never execute.
You always pass a non-empty string the the SP (it always starts with the text "Images/") so the IF will always fail to match an empty string.
Perhaps you wanted this:

IF (@poSmallImage != '')


这篇关于使用if-else语句在数据库中不更新相同的映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆