DragonRAD Forum
June 19, 2013, 02:03:13 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Primary Key Help  (Read 555 times)
skater007
Member
**
Posts: 80


View Profile
« on: May 29, 2012, 10:00:04 AM »

I need a primary key generated when a record is created on the handheld.  Unfortunately I cant seem to find a way to get it to work.  I wanted the key field to be populated by a script but textbox the script is to populate must be read only since its tied to the PK.  Is there any way to work around this?

Thanks

Andy
Logged
Rob Nicol
Seregon
****
Posts: 82


View Profile
« Reply #1 on: May 30, 2012, 05:37:16 PM »

It's best to use an auto-increment primary key in the database.  In your mobile app, don't touch the pk and DragonRAD will assign a temporary key on the device until the row is inserted into the database. At the end of the INSERT SQL statement, add a select to obtain the last inserted ID:

MySQL:
INSERT INTO MYTABLE (col1, col2) VALUES (val1, val2); :EXEC:; SELECT LAST_INSERT_ID();

SQLServer:
INSERT INTO MYTABLE (col1, col2) VALUES (val1, val2); SELECT SCOPE_IDENTITY();

Note: col1, col2 are NOT the primary key.  The primary key is not specified in the insert statement. It is returned to the device by the SELECT portion of the statement, and the device will replace the temporary key with the value provided by the database during the insertion.
Logged
skater007
Member
**
Posts: 80


View Profile
« Reply #2 on: December 12, 2012, 02:18:01 PM »

How would I set up the table then.
I have set up a table with an auto-increment key field in my sql database and set the key in the data table in DR to another field.  I still can't get the record to insert into my detail table.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!