Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
On click of 'getDetails' button I want to get details using substring from a column.
There is no error in my code but I feel there should be some wrong in the db.query.
Can some one sort it out?



C#
public void getDetails(View v)

{
    String s1=name.getText().toString();
    String sub1=s1.substring(0,s1.indexOf(s1));
    String s3= vivzHelper.getData(sub1);
    Message.message(this,s3);

}




public String getData(String name) {
SQLiteDatabase db = helper.getWritableDatabase();
String[] columns = {VivzHelper.NAME};
String[] selectionArgs = {name};
Cursor cursor= null;

cursor = db.query(VivzHelper.NAME, columns, VivzHelper.NAME + "=?", null, null, null, null, null);
StringBuffer buffer = new StringBuffer();
while(cursor.moveToNext())
{
int indexID=cursor.getColumnIndex(VivzHelper.UID);
int nameID=cursor.getInt(indexID);
int accountNameIDX=cursor.getColumnIndex(VivzHelper.NAME);
String accountName=cursor.getString((accountNameIDX));
buffer.append(nameID+" "+ accountName+"/n");

}
return buffer.toString();



}
Posted

1 solution

try closing the cursor before you return

Java
cusror.close();
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 15-Mar-15 5:13am    
I did as you said. Not working. Same problem.
Darren_vms 16-Mar-15 4:51am    
Can't see anything else wrong, what happens if you debug the routine ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900