Linq query error pulling blob image from database…object must implement IConvertible
質問
My query returns an error saying "Object must implement IConvertible". The error occurs on the .FirstOrDefault() line. I am trying to pull a blob image from a database and return it to the ajax call. I have been searching for 2 days for an answer and can't find anything.
[HttpGet]
//[Authorize]
public ActionResult getChartInfo(string ticker)
{
var db = new MarketSymmetricsSite.msxxdbDB();
System.Linq.IQueryable<string> gQuery = (System.Linq.IQueryable<string>)(from mg in db.Markets where mg.tickerID == ticker select mg.pGraph);
string mGraph = gQuery.FirstOrDefault(); ;
byte[] test = new byte[mGraph.Length];
char[] CharArray = mGraph.ToCharArray();
byte[] ByteArray = new byte[CharArray.Length];
for (int i = 0; i < CharArray.Length; i++)
{
ByteArray[i] = Convert.ToByte(CharArray);
}
return Json(ByteArray, JsonRequestBehavior.AllowGet);
}
解決 2
To solve this all I had to do was change the data type in the database from blob to binary and voila. Hope this will help anyone who may need it.
他のヒント
you need to use var and then convert image from binary so it an image file now
var img = (from mg in db.Markets where mg.tickerID == ticker select mg.pGraph).FirstOrDefault();
va rconvertedimage = ByteArrayToImage(img.Image.ToArray());
所属していません StackOverflow