Hi guys, im having some trouble updating a record store, its for an events application. The user inpus the event details , but i want to have an edit section so that they can retrieve whats storesd in the rs and then add to it or delete anything they want. Below i'll show the code for retreiving data from the rs. Below this ill show the update method.
protected void edit () {
txtName1 = new TextField("Name:", null, 15, TextField.ANY);
txtEvtDesc1 = new TextField("Description:", null, 30, TextField.ANY);
txtTown1 = new TextField("Town:", null, 20, TextField.ANY);
txtPlace1 = new TextField("Place:", null, 20, TextField.ANY);
txtstartDate1 = new TextField("End Date:", null, 20, TextField.ANY);
txtendDate1 = new TextField("Start Date:", null, 20, TextField.ANY);
txtAdComs1= new TextField("Additional Comments:", null, 20, TextField.ANY);
// txtName = new TextField("Name:", null, 15, TextField.ANY);
// txtEvtDesc = new TextField("Description:", null, 30, TextField.ANY);
//txtTown = new TextField("Town:", null, 20, TextField.ANY);
// txtPlace = new TextField("Place:", null, 20, TextField.ANY);
// txtstartDate = new TextField("End Date:", null, 20, TextField.ANY);
// txtendDate = new TextField("Start Date:", null, 20, TextField.ANY);
// txtAdComs= new TextField("Additional Comments:", null, 20, TextField.ANY);
mListForm.deleteAll(); // clear the form
try {
RecordStore rs = RecordStore.openRecordStore("Details", true);
RecordEnumeration re = rs.enumerateRecords(null, null, false);
while (re.hasNextElement()) {
byte [] recordBuffer = re.nextRecord();
String record = new String(recordBuffer);
// extract the name and the age from the record
int endOfName = record.indexOf(";");
int endOfEvtDesc = record.indexOf(";", endOfName + 1);
int endOfTown = record.indexOf(";",endOfEvtDesc + 1);
int endOfPlace = record.indexOf(";",endOfTown + 1);
int endOfStart= record.indexOf(";",endOfPlace + 1);
int endOfend= record.indexOf(";",endOfStart + 1);
int endOfadComs= record.length();
txtName1.setString( record.substring(0, endOfName));
txtEvtDesc1.setString( record.substring(endOfName + 1, endOfEvtDesc));
txtTown1.setString( record.substring( endOfEvtDesc +1 ,endOfTown));
txtPlace1.setString( record.substring( endOfTown+1 ,endOfPlace));
txtstartDate1.setString( record.substring( endOfPlace +1 ,endOfStart));
txtendDate1.setString( record.substring( endOfStart +1 ,endOfend));
txtAdComs1.setString( record.substring( endOfend +1 ,endOfadComs));
// txtEvtDesc.setString(record.substring(endOfEvtDesc));
// txtTown.setString(record.substring(endOfTown));
// txtPlace.setString(record.substring(endOfPlace));
// txtstartDate.setString(record.substring(endOfStart));
// txtendDate.setString(record.substring(endOfend));
}
rs.closeRecordStore();
}
catch(Exception e){
mAlertConfirmDetailsSaved.setString("Couldn't read details");
System.err.println("Error accessing database");
}
mEdit.append(txtName1);
mEdit.append(txtEvtDesc1);
mEdit.append(txtTown1);
mEdit.append(txtPlace1);
mEdit.append(txtstartDate1);
mEdit.append(txtendDate1);
mEdit.append(txtAdComs1);
mDisplay.setCurrent(mEdit);
}
Update method protected void updateData() {
strName = txtName1.getString();
strEvtDesc = txtEvtDesc1.getString();
strTown = txtTown1.getString();
strPlace = txtPlace1.getString();
strStart= txtstartDate1.getString();
strEnd= txtendDate1.getString();
strAdComs= txtAdComs1.getString();
if (listOfIDs1 != null) {
try {
RecordStore rs = RecordStore.openRecordStore("Details", true);
String detailsToAdd = strName + ";" + strEvtDesc + ";" + strTown +";" +strPlace +";"+ strStart +";"+ strEnd + ";"+ strAdComs;
byte [] detailsBuffer = detailsToAdd.getBytes();
for (Enumeration e = listOfIDs1.elements() ; e.hasMoreElements() ;) {
int id = ((Integer)e.nextElement()).intValue();
rs.setRecord(id,detailsBuffer,0,detailsBuffer.length +1 );
}
rs.closeRecordStore();
}
catch (Exception e) { // an error occured saving
// mAlertConfirmDetailsSaved.setString("Couldn't save details");
System.err.println("Error saving to database");
}}
// mDisplay.setCurrent(mDataEntryForm);
}
Anyone have any ideas?