简体   繁体   English

在SQL Server中为图像数据类型在ASP.NET中重置值

[英]Reset value in ASP.NET for Image data type in SQL Server

In ASP.NET I wish to empty/clear/reset the contents on an Image data type in SQL Server. 在ASP.NET中,我希望清空/清除/重置SQL Server中Image数据类型上的内容。 I will then later check to see if this column is empty/null - if not, I will output the image. 然后,我稍后将检查此列是否为空/空-如果不是,我将输出图像。

Can you tell me the necessary C#? 你能告诉我必要的C#吗? Here is what I have presently... 这是我目前所拥有的...

newsItem.Image1 = null;
dataContext.SubmitChanges();

The above actually gives me "0x" when I look through SQL Server Management Studio, so its not actually empty. 当我通过SQL Server Management Studio查看时,上面的内容实际上给了我“ 0x”,因此它实际上不是空的。

Many thanks! 非常感谢!

Couple things come to mind: 几件事想到:

  • In your database, is Image nullable? 在您的数据库中,Image是否可以为空?
  • You may have to remove and recreate the entire row of that table to ensure that the field is removed. 您可能必须删除并重新创建该表的整个行,以确保删除了该字段。

  • If it is Nullable in DB then use 如果它在数据库中为Nullable,则使用

    newsItem.Image1= null;
    

    else 其他

    newsItem.Image1= new Binary( new byte[0] );
    

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM