Alan, in the first place thanks for your cooperation. Here I will post again
some code that I changed according of what you said. I must remember
everyone that I am new, so please I just want a code snippet that Opens a
Database and Reads the Records through it. I show you this code in order to
show you that I try to search a solution but I cannot, it is not that I do
not want to do the work. Hope you and everyone can help,
Thanks

 static DmOpenRef  AddressDB;
 static LocalID  AddressDBID;
 static UInt16   nRecords;
 static Err   err;
 static MemHandle memH;
 static UInt16  i;


 AddressDBID = DmFindDatabase(0, "TABLA");
//I get a valid ID for the Database
 AddressDB = DmOpenDatabase(0, AddressDBID, dmModeReadOnly);
//I get valid pointer

 nRecords = DmNumRecords(AddressDB);
//I get exactly the number of records


 for (i = 0; i < nRecords; i++)
 {
   //here is where I have the problem, I do not know if I am doing this ok.
  memH = DmQueryRecord(AddressDB,i);
  Cliente = (DatosCliente *) MemHandleLock(memH);
//when I read Cliente->Nombre, it has anything except what I am looking for,
the same happens with
//Cliente->NCliente, I do not know where that value comes from, because it
is not the same as what the
//database has.
  FrmCustomAlert(CustomAlert,Cliente->Nombre, Cliente->NCliente,"");
  MemHandleUnlock(memH);
 }

 DmCloseDatabase(AddressDB);


}

-----Mensaje original-----
De: P. Alan Johnson <[EMAIL PROTECTED]>
Para: Palm Developer Forum <[EMAIL PROTECTED]>
Fecha: Sábado, 27 de Enero de 2001 08:13 p.m.
Asunto: RE: Databases


>Comments below.
>--Alan
>
>> Hi to all. I have sent a code regarding databases. I have made some
>> modifications to it, but yet it does not work, pleeeeeeeeaseeeeeeeeeeeee
>> help, I have been all the day with this and I cannot solve it!
>> The Database consists on:
>> Cliente (char *) NCliente (Char *)
>> ForExample
>> Nicolas    Raitman
>> Juan         McKeuy
>>
>>
>> typedef struct
>> {
>> char   * Nombre;
>> char  * NCliente;
>> } DatosCliente;
>>
>> DatosCliente * Cliente;
>>
>> static DmOpenRef  AddressDB;
>> static LocalID  AddressDBID;
>> static UInt16   nRecords;
>> static Err   err;
>> static MemHandle mHandle;
>> static UInt16  i;
>>
>>
>> AddressDBID = DmFindDatabase(0, "COMPOSICION");
>Is a value stored in AddressDBID? In other words, did your database get
>found?
>
>> AddressDB = DmOpenDatabase(0, AddressDBID, dmModeReadOnly);
>Is AddressDB not NULL?
>
>> nRecords = DmNumRecords(AddressDB);
>Does nRecords hold a value greater than 0?
>
>
>> for (i = 0; i < nRecords; i++)
>> {
>>
>>   Cliente = (DatosCliente *)
>> MemHandleLock(MemHandleNew(sizeof(DatosCliente)));
>God knows why you are allocating memory then not releasing it. Perhaps you
>are later on but this isn't obvious.
>
>>   Cliente = (DatosCliente *) DmQueryRecord(AddressDB, i);
>DmQueryRecord returns a handle to a moveable memory location. The sequence
>of events should normally be: Get a handle, Lock the handle to get a
pointer
>to your data type (struct, char, int, whatever you stored), use the data,
>Unlock the handle, go on your merry way.
>
>>   DmReleaseRecord(AddressDB, i, false);
>As the documentation clearly says, use this on records that you've accessed
>utilizing the DmGetRecord function. You didn't use DmGetRecord.
>> }
>>
>>
>>
>> DmCloseDatabase(AddressDB);
>>
>> What's the problem? I cannot get the data the it is on the database,
>> pleaaaaaasseeeee what am I doing wrong?
>>
>>
>>
>>
>>
>>
>> --
>> For information on using the Palm Developer Forums, or to
>> unsubscribe, please see http://www.palmos.com/dev/tech/support/forums/
>>
>
>
>--
>For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to