error while displaying the row values from database ..

i am getting following error in unity while retrieving row values.

i am using sqlite3 as the database handling tool.

The error occured in the line"readArray.Push(reader.GetString(0)); // Fill array with all matches" in following code.

"
InvalidCastException: Cannot cast from source type to destination type.

"
InvalidCastException: Cannot cast from source type to destination type."

Mono.Data.Sqlite.SqliteDataReader.VerifyType (Int32 i, DbType typ)

Mono.Data.Sqlite.SqliteDataReader.GetString (Int32 i)

dbAccess.SingleSelectWhere (System.String tableName, System.String itemToSelect,

System.String wCol, System.String wPar, System.String wValue) (at Assets/Test video/Log in pages/dbAccess.js:141)"

i have used the following function to fetch the table values.

var databaseData = new Array();

 function SingleSelectWhere(tableName : String, itemToSelect : String, wCol : String, wPar : String, wValue : String){ // Selects a single Item
        var query : String;
        query = "SELECT " + itemToSelect + " FROM " + tableName + " WHERE " + wCol + wPar + wValue; 
		
        dbcmd = dbcon.CreateCommand();
        dbcmd.CommandText = query; 
        reader = dbcmd.ExecuteReader();
        var readArray = new Array();
        while(reader.Read()){ 
            readArray.Push(reader.GetString(0)); // Fill array with all matches
        }
        return readArray; // return matches
    }

function OnGUI(){
GUI.BeginGroup(Rect(0,0,1200,675));
   			
   			databaseData=SingleSelectWhere();
   			
       		var lenn :int =0;
        	lenn= databaseData.length;
    		GUI.Label(Rect(440,280,50,50),databaseData[lenn-1]+"/8",welcomeLabelStyle);
         
		GUI.EndGroup();
}



  function SingleSelectWhere()
    		  {
    		  return db.SingleSelectWhere(TableName,"MCQScore","userCode","=","userCode");
    				
    			}

please some one trace this code and let me know how can i remove this error from my
code…

Thanks

Hi,

the error must occur because your field contains a null value as you’re expecting a string.
I’m still searching a way to check if value is null before doing the GetString…

regards

Hi,

Pb occured because your field must certainly contain a null value as you’re expecting a string.

Simply test if value is null before doing the GetString

if (!reader.IsDBNull(0))readArray.Push(reader.GetString(0));

Regards