当我从数据库表中检索图像时,出现以下错误.图像以二进制格式存储在表中 [英] while i am retrieving the image from the db table i am getting the below error.image is stored in the table in binary format

查看:40
本文介绍了当我从数据库表中检索图像时,出现以下错误.图像以二进制格式存储在表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

byte[] bytes = (byte[])drc[0]["img"];


这里drc是数据行集合

错误信息:

无法将类型为"System.DBNull"的对象转换为类型为"System.Byte []".


here drc is the data row collection

erro info:

Unable to cast object of type ''System.DBNull'' to type ''System.Byte[]''.

推荐答案

这很明显:错误消息非常明确.
您的SQL查询返回第0行的"img"空白字段.

您的数据库不包含图像,或者您的查询错误.
It''s pretty obvious: the error message is very explicit.
Your SQL query is returning an empty field for "img" on row 0.

Either your database does not contain an image, or your query is wrong.


要在标记中进行操作:
to do it in markup:
<telerik:radbinaryimage runat="server" id="rbi" datavalue="<%# ((System.Data.Linq.Binary) Eval("imageFull")).ToArray() %>" xmlns:telerik="#unknown" /> 


或动态执行:


or do it dynamically:

var product = (from p in products
               select p).First();//.First() = LIMIT 1 in sql, which in turn makes the product variable singular and usable like this:
rsi.DataValue = product.imageFull.ToArray();


这篇关于当我从数据库表中检索图像时,出现以下错误.图像以二进制格式存储在表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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