用于在C#中验证的图片框图像 [英] Picture box image for validation in C#

查看:69
本文介绍了用于在C#中验证的图片框图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨每一个。

我正在使用图片框将图像保存在数据库中但是现在我想要的是如果没有图像眉毛那么它会在数据库中的图像属性中保存空值。任何人告诉我我该怎么做

我正在使用此代码在SQL Server 2014中保存图像



什么我试过了:



 MemoryStream ms = new MemoryStream(); 
pictureBox1.Image.Save(ms,pictureBox1.Image.RawFormat);
byte [] a = ms.GetBuffer();
ms.Close();
cmd.Parameters.AddWithValue(@ LogoImage,a);

解决方案

假设您的数据库在列中接受NULL值:

  byte  [] a =  null ; 
if (pictureBox1.Image!= null
{
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms,pictureBox1.Image.RawFormat);
a = ms.GetBuffer();
ms.Close();
}
cmd.Parameters.AddWithValue( @ LogoImage,a) ;


hi every one.
I'm using picture box to save image in database but now i want if there is no image brows then it save null value in image attribute in database. Any one tell me how can i do this
I'm using this code to save image in SQL server 2014

What I have tried:

MemoryStream ms = new MemoryStream();
                           pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
                           byte[] a = ms.GetBuffer();
                           ms.Close();
                           cmd.Parameters.AddWithValue("@LogoImage", a);

解决方案

Assuming that your DB accepts NULL values in the column:

byte[] a = null;
if (pictureBox1.Image != null)
    {
    MemoryStream ms = new MemoryStream();
    pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
    a = ms.GetBuffer();
    ms.Close();
    }
cmd.Parameters.AddWithValue("@LogoImage", a);


这篇关于用于在C#中验证的图片框图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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