tags:

views:

542

answers:

0

I basically want my Midlet the ability to edit records.

I have this code

the information is added as follows

 protected void searchForNameToEdit()
 {
          Editrecord.deleteAll();

    try
    {

        rs = RecordStore.openRecordStore("Detail", true);
        RecordEnumeration re = rs.enumerateRecords(new NameMatcher(EditSearch.getString()), null, false);
        while (re.hasNextElement())
        {
            byte [] recordBuffer = re.nextRecord();
            String record = new String(recordBuffer);


            int endOfName = record.indexOf(";");
            int endOfDesc = record.indexOf(";" , endOfName + 1);
            int endOfTown = record.indexOf(";", endOfDesc + 1);
            int endOfPlace = record.indexOf(";", endOfTown + 1);
            int endOfSDay = record.indexOf("/", endOfPlace +1);
            int endOfSMonth = record.indexOf("/",endOfSDay + 1);
            int endOfSYear = record.indexOf(";", endOfSMonth + 1);
            int endOfEDay = record.indexOf("/", endOfSYear + 1);
            int endOfEMonth = record.indexOf("/", endOfEDay + 1);
            int endOfEYear = record.indexOf(";", endOfEMonth + 1);
            int endOfComment = record.indexOf(";", endOfEYear + 1);
            int endOfRating = record.indexOf (";", endOfComment + 1);
            int endOfReview = record.indexOf (";", endOfRating + 1);


            String Name = record.substring(0, endOfName);
            String Desc = record.substring(endOfName + 1, endOfDesc);
            String Town = record.substring(endOfDesc + 1, endOfTown);
            String Place= record.substring(endOfTown + 1, endOfPlace);
            String SDay = record.substring(endOfPlace +1, endOfSDay);
            String SMonth = record.substring(endOfSDay + 1, endOfSMonth);
            String SYear = record.substring(endOfSMonth + 1, endOfSYear);
            String EDay = record.substring(endOfSYear + 1, endOfEDay);
            String EMonth = record.substring(endOfEDay + 1, endOfEMonth);
            String EYear = record.substring(endOfEMonth + 1, endOfEYear);
            String Comment = record.substring(endOfEYear + 1, endOfComment);
            String Rating = record.substring(endOfComment + 1, endOfRating);
            String Review = record.substring(endOfRating + 1, endOfReview);


            EtxtName = new TextField("Name of Event: ", Name, 15, TextField.ANY);
            EdescEvent = new TextField("Describe the Event : ", Desc, 250, TextField.ANY);
            EtownEvent = new TextField("Name of Town : ", Town, 50, TextField.ANY);
            EplaceEvent = new TextField("Name of Place : ", Place, 25, TextField.ANY);
            EcommentEvent = new TextField("Any comments : ", Comment, 300, TextField.ANY);
            EStartDate = new TextField("Start Date : ", SDay + "/" + SMonth + "/" + SYear +";", 300, TextField.ANY);
            EEndDate =new TextField("End Date : ", EDay + "/" + EMonth + "/" + EYear +";", 300, TextField.ANY);
            EEventRating = new TextField("Event Rating : ", Rating, 10, TextField.ANY);
            EOverallReview = new TextField("Overall Review : ", Review, 300, TextField.ANY);


            Editrecord.append(EtxtName);
            Editrecord.append(EdescEvent);
            Editrecord.append(EtownEvent);
            Editrecord.append(EplaceEvent);
            Editrecord.append(EStartDate);
           // Editrecord.append("Start Date; " + SDay + "/" + SMonth + "/" + SYear);
            //Editrecord.append("End Date; " + EDay + "/" + EMonth + "/" + EYear);
            Editrecord.append(EEndDate);
            Editrecord.append(EcommentEvent);
            Editrecord.append(EEventRating);
            Editrecord.append(EOverallReview);




    }
        rs.closeRecordStore();
    }

    catch(Exception e)
    {
        mAlertConfirmDetailsSaved.setString("Couldn't read details");
        System.err.println("Error accessing database");
    }

    Display.setCurrent(Editrecord);

}

and this is the method to perform the update

protected void PerformUpdate()
{
    int id;

    strEName = EtxtName.getString();
    strEDescEvent = EdescEvent.getString();
    strETown = EtownEvent.getString();
    strEPlace = EplaceEvent.getString();

    strStartDate = EStartDate.getString();

    strEndDate = EEndDate.getString();

    strECommentE = EcommentEvent.getString();
    strERating = EEventRating.getString();
    strEReview = EOverallReview.getString();


        String detailsToUpdate = strEName + ";" +"\n"+
                                 strEDescEvent + ";" + "\n"+
                                 strETown + ";" + "\n" +
                                 strEPlace + ";"+ "\n" +
                                 strEStartDate + ";" + "\n" +
                                 strEEndDate + ";" + "\n" +
                                 strECommentE + ";"+ "\n" +
                                 strERating + ";"+ "\n" +
                                 strEReview + ";";

    if (listOfIDs != null)
    {

        try {
            //RecordStore
                    rs = RecordStore.openRecordStore("Detail", true);
            for (Enumeration e = listOfIDs.elements() ; e.hasMoreElements() ;)
            {
                id  = ((Integer)e.nextElement()).intValue();
                byte [] detailsBuffer = detailsToUpdate.getBytes();
             rs.setRecord(id,detailsBuffer, 0, detailsBuffer.length);

            }

            rs.closeRecordStore();

            mAlertDeleteDone.setString("  Selected record updated");

            }
        catch(Exception e)
            {
            mAlertDeleteDone.setString("Couldn't update record");
            System.err.println("Error accessing database");
            }

    } 
    else
    {
        mAlertDeleteDone.setString("No records to update");
    }

    Display.setCurrent(mAlertDeleteDone, mOpeningForm);
}

All I keep getting is the else outcome of No records to update and I have no reason why?

Please help or send me a helpful tutorial thanks