我的insert databasehelper方法仅在sqlite表中插入最后一个contentvalue

时间:2019-07-09 09:41:25

标签: android

insert方法仅插入grandtotal的值,但不插入其他列的其他值

public long insertNote(String requestid2,String requester2,String department2,String grandtotal2){         //获取可写数据库,因为我们要写数据         SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();

    // `id` and `timestamp` will be inserted automatically.
    // no need to add them
    values.put(Requisition.COLUMN_REQUSTID, requestid2);
    values.put(Requisition.COLUMN_REQUSTER, requester2);
    values.put(Requisition.COLUMN_DEPARTMENT, department2);
    values.put(Requisition.COLUMN_GRANDTOTAL, grandtotal2);


    // insert row
    long id = db.insert(Requisition.TABLE_NAME, null, values);



    // close db connection
    db.close();

    // return newly inserted row id
   return id;
}

以上是方法 波纹管是否正在使用 私有无效xmlimport(){        XmlResourceParser parser = getResources()。getXml(R.xml.requisitions);

   //DatabaseHelper myDbHelper = null;
   try {
       //myDbHelper = new DatabaseHelper(this);

       while (parser.next() != XmlPullParser.END_TAG) {
           if (parser.getEventType() != XmlPullParser.START_TAG) {
               continue;
           }
           String name = parser.getName();
           if (name.equals("requisition")) {
               String requestid1 = null, requester1 = null, department1 = null;
               String grandtotal1 = null;
               while (parser.next() != XmlPullParser.END_TAG) {
                   if (parser.getEventType() != XmlPullParser.START_TAG) {
                       continue;
                   }
                   name = parser.getName();
                   if (name.equals("rqnumber")) {
                       requestid1 = readText(parser);
                   } else if (name.equals("title")) {
                       requester1 = readText(parser);
                   } else if (name.equals("dpname")) {
                       department1 = readText(parser);
                   } else if (name.equals("grandtotal")) {
                       grandtotal1 = readText(parser);
                   }
               }
               // myDbHelper.insertNote(requestid, requester, department,grandtotal);
               // createXmlimport(requestid1, requester1, department1, grandtotal1);
               //db.insertRequisition(requestid1, requester1, department1, grandtotal1);
                db.insertNote(requestid1, requester1, department1, grandtotal1);


           }
       }
   } catch (XmlPullParserException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
   } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
   }

}

0 个答案:

没有答案