Linq query error pulling blob image from database…object must implement IConvertible

StackOverflow https://stackoverflow.com/questions/10527135

  •  07-06-2021
  •  | 
  •  

문제

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());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top