无法在textbox android中显示来自数据库的数据

时间:2014-02-27 04:29:41

标签: java android sqlite

我在包含已存在的数据的数据库中遇到问题,但数据未出现在文本框中。请帮忙

这是来自Form.java的数据

String modul; 
        String itemreg;
        modul = dataSource.getModule(assignmentid,orderid,productmoduleid,productdetailid);
        //itemreg = dataSource.getItemreg(productmoduleid, productdetailid);
        if(Globals.modul==null){
            Globals.modul=modul;
        }
        String namamodul;
        namamodul=dataSource.getModul1(productmoduleid);
        edModul.setText(namamodul);

这是dbdatasource.java

public String getModule(String assignmentid, String orderid, String productmoduleid, String productdetailid){
    Cursor cursor = database.query(DBHelper.ASSIGNMENT_ORDER_DETAIL,allAssignemntOrderDetail, DBHelper.ASSIGNMENT_ID +"= 'assgn1' and "+DBHelper.ORDER_ID +"= 'ord1'", null, null, null, null);
    cursor.moveToFirst();
    AssignmentOrderDetail = cursor.getString(cursor.getColumnIndex(DBHelper.PRODUCT_MODULE_ID));
    cursor.close();
    return AssignmentOrderDetail;
}

public String getModul1(String productmoduleid){
    String productmodul ;
    Cursor cursor = database.query(DBHelper.PRODUCT_MODULE,allProductModule, DBHelper.PRODUCT_MODULE_ID +"='"+Globals.modul+"'", null, null, null, null);
    cursor.moveToFirst();
    productmodul = cursor.getString(cursor.getColumnIndex(DBHelper.PRODUCT_MODULE_DESC));
    cursor.close();
    return productmodul;
}

2 个答案:

答案 0 :(得分:0)

尝试使用以下代码:

Cursor cursor = null;
String TABLE_NAME = "yourTableName";
String[] allColumns = {"coloumn1","coloumn2","coloumn3"};
String whereClause = "coloumn1"+"=?";
String[] whereArgs = new String[] {method_parameter};

如下所示:

private Cursor getData(String param_id)
{
try{
sqliteDb = appDb.getWritableDatabase();
if(sqliteDb.isOpen())
{
   cursor = sqliteDb.query(TABLE_NAME, whereClause, whereArgs);
}
}catch(Exception ex)
{
    b = false;
    ex.printStackTrace();
}
return cursor;
}

答案 1 :(得分:0)

尝试这可能会有所帮助:

try{

  Cursor cursor = 
         database.query(DBHelper.ASSIGNMENT_ORDER_DETAIL,allAssignemntOrderDetail,
         DBHelper.ASSIGNMENT_ID +"= 'assgn1' and "+DBHelper.ORDER_ID +"= 'ord1'", 
         null, null, null, null);

   if(cursor != null) {
       cursor.moveToFirst();
       AssignmentOrderDetail =
            cursor.getString(cursor.getColumnIndex(DBHelper.PRODUCT_MODULE_ID));
   }
   return AssignmentOrderDetail;
}finally {
     cursor.close();
}