mardi 14 juillet 2015

SQLite query on inner join is not working .The cursor is showing null in mono for android

I want to fill my ListView by selecting the rows after using inner join in the sqlite query.

In my MainActivity

MyDatabase md = new MyDatabase ("test1");

GetICursor();

    protected void GetICursor (string date){   
                Android.Database.ICursor ic = md.GetRecordCursor (date);  
                if (ic != null) {  
                    ic.MoveToFirst ();  
                    ListView lv = FindViewById<ListView> (Resource.Id.listViewDB);  
                    string[] from = new string[] {"Time","Place","Person"};  
                    int[] to = new int[] {  
                        Resource.Id.time,  
                        Resource.Id.place,  
                        Resource.Id.person,  
                    };  
                    SimpleCursorAdapter sca = new SimpleCursorAdapter (this,Resource.Layout.ListView, ic, from, to);     
                    lv.Adapter = sca;  
            } 

        }


The database contains 3 tables

Meeting
-------
Columns -> _id, Date, Time, PersonID, PlaceID

User
----
Columns -> _id, PersonName

Area
----
Columns -> _id, Place

In my Database class
----------------------

private SQLiteDatabase sqld;
private string sSQLQuery;


public Android.Database.ICursor GetRecordCursor (string sdate)   
{   
    Android.Database.ICursor ic = null;   
    try {   
        sSQLQuery = "SELECT Meeting.Time, User.PersonName, Area.Place" +   
                    "FROM Meeting " +   
                    "INNER JOIN User " +   
                    "ON Meeting.PersonID = User._id " +   
                    "INNER JOIN Area" +   
                    "ON Meeting.PlaceID = Area._id" +   
                    "WHERE Meeting.Date = '" + sdate + "';";   
        ic = sqld.RawQuery (sSQLQuery, null);   
    } 
    catch (SQLiteException) {}   
    return ic;   
}

When I debug the code, the variable ic shows null.

What am I doing wrong ?

Aucun commentaire:

Enregistrer un commentaire