Click here to Skip to main content
15,917,565 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
byte[] bytes = (byte[])drc[0]["img"];

here drc is the data row collection

erro info:

Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'.
Posted
Updated 11-Apr-12 23:01pm
v2

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.
 
Share this answer
 
to do it in markup:
ASP.NET
<telerik:radbinaryimage runat="server" id="rbi" datavalue="<%# ((System.Data.Linq.Binary) Eval("imageFull")).ToArray() %>" xmlns:telerik="#unknown" /> 

or do it dynamically:
C#
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();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900