loading image as a blob from Sqlite,loading image from Sqlite

Hi guys, this is my first time using sqlite, i managed to display the text, but the image shows a red question mark, which means that the texture couldn’t be retrieved, however the byte array is not empty, so i dont know what to do.

Here is my code for reading the database :

private void readQuestionsFromDB(){

    string conn = "URI=file:" + Application.dataPath + "/quizdb.s3db"; //Path to database.
 IDbConnection dbconn;
 dbconn = (IDbConnection) new SqliteConnection(conn);
 dbconn.Open(); //Open connection to the database.
 IDbCommand dbcmd = dbconn.CreateCommand();
 string sqlQuery = "SELECT id, statement, answer, image " + "FROM questions";
 dbcmd.CommandText = sqlQuery;
 IDataReader reader = dbcmd.ExecuteReader();

 while (reader.Read())
 {
    string statement = reader.GetString(1);

    answerint = reader.GetInt32(2);

    byte[] img = (byte[])reader["image"];

    Question q = new Question(statement, answer, img);
    questions.Add(q);

 }
 reader.Close();
 reader = null;
 dbcmd.Dispose();
 dbcmd = null;
 dbconn.Close();
 dbconn = null;

}

And here is how i try to display it as an image in the start method :

readQuestionsFromDB();  

   statement.text = questions[0].statement;

   Texture2D tex = new Texture2D(800,400); //image is 800/400
    tex.LoadImage(questions[0].image);
    image.GetComponent<Image>().sprite = Sprite.Create(tex, new Rect(0,0,tex.width,tex.height),new Vector2(0.5f, 0.5f));

Here is what i get, the text displays correctly, but not the image :

Please help me, i have looked everywhere and can’t find a solution, thank you in advance!

What kind of “image” did you store in your database? You know that Unity can only load jpg or png files natively at runtime.

Besides that what have you already done to debug your issue? Have you checked if whatever you get back from reader["image"] is actually not null and that the byte array has a non zero size? Likewise tex.LoadImage now returns a bool if the loading was successful or not.

ps: There’s no need / point in creating an empty Texture that is that large when you use LoadImage. The whole content is replaced by the loaded image (if the loading is successful or course). The “question mark” texture generally indicates an error when loading the image. So either your data is corrupted in some way (no data, wrong data) or you use a non supported texture format to begin with.