如何检查图像dataype是否有价值或使用vb.net形成sql server? [英] How to check image dataype have value or not form sql server using vb.net ?

查看:70
本文介绍了如何检查图像dataype是否有价值或使用vb.net形成sql server?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai

i am sql server中的存储图像作为sql server中的二进制文件,我的sql字段数据类型是一个图像,因此可以在该列中保存二进制格式。如果不保存任何图像(<二进制数据) =>)在该列中,如果我在sql server中看到它显示NULL字,但如果我检索该列,则为空行。



我的问题是如何检查该列是否有二进制数据,bcz



1.如果我检查行数,它将显示空白行,因此计数为1 - -cant check count。

2.如果我检查NULL字,它将显示无法将类型'System.DBNull'的对象强制转换为'System.Byte []' - 不能检查NULL字

3.如果我检查是否有相同的错误抛出。



那么我如何检查这个图像数据类型字段vb.net使用if条件?





请尽快回复



问候

Aravind

Hai
i am store image in sql server as binary in sql server,my sql field datatype ia image,so can save binary format in that column.if not save any image(<binary data="">) in that column,if i see in sql server it show "NULL" word,but if i retrieve that column,its blank row.

my question is how to check that column have binary data or not,bcz

1.if i check row count,it will show blank row so count is 1 ---cant check count.
2.If i check "NULL" word,it will show "Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'" -- cant check "NULL" word
3.if i check Is Nothing same error throws.

So how i check this image datatype field in vb.net using if condition ?


Pls reply asap

Regards
Aravind

推荐答案

using System.Drawing;
if (dr["Photo"].ToString() != "")
{
    Byte[] image = (Byte[])(dr["Photo"]);
    string src = "data:image/jpeg;base64," + Convert.ToBase64String(image);
    picPhoto.ImageUrl = src;
}
else
{
 //if you want to set some default image
picPhoto.ImageUrl = "~/images/DefaultImg.png";
}



VB


VB

If dr("Photo").ToString() <> "" Then
    Dim image As [Byte]() = DirectCast(dr("Photo"), [Byte]())
    Dim src As String = "data:image/jpeg;base64," + Convert.ToBase64String(image)
    picPhoto.ImageUrl = src
Else
    picPhoto.ImageUrl = "~/images/DefaultImg.png"
End If



i解决了t他的问题是通过以下代码,在我的数据表中如果我得到二进制值然后它不为空,如果datatable得到空值或空行然后那行id db null。





Hi i solved this problem by followings codes,in my datatable if i get binary values then it not empty,if datatable get null value or blank row then that row id db null.


Dim data = objdtr.Rows(0)("LogoImg")

If (TypeOf data Is DBNull) Then
   PictureBox6.Image = Global.Hospital.My.Resources.Resources.P123__half_size_
Else
'Here i download byte and convert into image and passed to PictureBox6 image
End IF





我会节省png i在SQL Server中作为二进制格式的mage,所以只能检索字节并再次转换成图像并在任何地方使用它。有时候图像列是空的。



i am选择那个列并填入datatable并在数据中获取该值,我检查它的数据类型是否为dbnull,如果为null我将从资源文件夹传递默认图像,如果没有则转换字节和图像并传递给picturebox。



为什么我不能直接检查数据是否为空,或行数或数据=(双引号),bcz显示空白行,所以不能count,如果检查NULL或它显示错误,如System.DBNull,键入'System.Byte []。





问候

Aravind



I will save png image in sql server as binary format,so only can retrieve bytes and convert into image again and use it in any place.some time that image column is empty.

i am select that column and fill in datatable and get that value in data,and i check it like type of data is dbnull or not,if it is null i will pass default image from resource folder,if not then convert byte and image and pass to picturebox.

Why i cant check directly data is null or not,or row count or data ="" (double quots),bcz it show blank row ,so cant count,if it is check "NULL" or "" it show error like "System.DBNull' to type 'System.Byte[]".


Regards
Aravind


检查字节数组的长度是否大于0。
Check if the byte array has length greater than 0.


这篇关于如何检查图像dataype是否有价值或使用vb.net形成sql server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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