title: in iphone how to get Sqlite last insert row id?
body: <p>I am making an application where i want to use update query?</p>
  
  <p>In my application i have two stages to complete the registration process</p>
  
  <p>in page1 i have registration form and one submit button?</p>
  
  <p>on click of submit button all the details should get insert into my sqlite table.</p>
  
  <p>in page2 i have confirmation page and one edit and continue button?</p>
  
  <p>all the value saved in  a table should be view by the user on this page and if he want's to make any change he should be able to do that. once user had edited some value and he press continue button all the value insert should get updated?</p>
  
  <p>but i have try doing this but i am not able to update the last enter value?</p>
  
  <p>following is my code page1 insert code:</p>
  
  <pre><code>-(void)submit
  {
  
      if( ([UserName.text isEqualToString:@""]) || ([Password.text isEqualToString:@""]) || 
          ([ConfirmPassword.text isEqualToString:@""]) || ([Name.text isEqualToString:@""]) || 
          ([Email.text isEqualToString:@""]) || ([ContactNO.text isEqualToString:@""]) || 
          ([MobileNo.text isEqualToString:@""]) || ([Address.text isEqualToString:@""]) )
  
      {
  
          UIAlertView *ErrorAlert = [[UIAlertView alloc] initWithTitle:@"Error!!" 
                                                                   message:@"Please fill in the details." delegate:nil
                                                         cancelButtonTitle:@"OK"
                                                         otherButtonTitles:nil, nil];
              [ErrorAlert show];
              [ErrorAlert release];
          }
          else 
          {
              Confirmation_form *conForm = [[Confirmation_form alloc] initWithNibName:@"Confirmation_form" bundle:nil];
              conForm.data = UserName.text;
              conForm.data1 = Password.text;
              conForm.data2 = ConfirmPassword.text;
              conForm.data3 = Name.text;
              conForm.data4 = Email.text;
              conForm.data5 = ContactNO.text;
              conForm.data6 = MobileNo.text;
              conForm.data7 = Address.text;
  
  
              sqlite3_stmt  *statement;
              const char *dbpath = [databasePath UTF8String];
              if (sqlite3_open(dbpath, &amp;test1DB) == SQLITE_OK)
              {
  
  
  
                  NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO test(UserName, Password, ConfirmPassword, Name, Email, ContactNO, MobileNo, Address) VALUES (\"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\")",UserName.text, Password.text, ConfirmPassword.text, Name.text, Email.text, ContactNO.text, MobileNo.text, Address.text];
                  const char *insert_stmt = [insertSQL UTF8String];
                  sqlite3_prepare_v2(test1DB, insert_stmt, -1, &amp;statement, NULL);
                  if(sqlite3_step(statement) == SQLITE_DONE)
                  {
                      //status.text = @"Contact added";
                      UserName.text = @"";
                      Password.text = @"";
                      ConfirmPassword.text = @"";
                      Name.text = @"";
                      Email.text = @"";
                      ContactNO.text = @"";
                      MobileNo.text = @"";
                      Address.text = @"";
  
  
                      sqlite3_last_insert_rowid;
                      rowID = sqlite3_last_insert_rowid(test1DB);
                      NSLog(@"last inserted rowId = %d",rowID);
  
                      sqlite3_reset(statement);
                      sqlite3_finalize(statement);
                      sqlite3_close(test1DB);
  
  
                      [self.navigationController pushViewController:conForm animated:YES];
  
                  }                   
              }
  
  
          }
      }
  </code></pre>
  
  <p>from the above code i am able to get the row id but i am not able to use that rowid in update query</p>
  
  <p>following is my code page2 Update code:</p>
  
  <pre><code>-(IBAction)Update;
  {
  
  sqlite3_stmt  *statement;
  const char *dbpath = [databasePath UTF8String];
  if (sqlite3_open(dbpath, &amp;test1DB) == SQLITE_OK)
  {
      NSString *insertSQL = [NSString stringWithFormat:@"UPDATE test SET UserName='%@',Password='%@',ConfirmPassword='%@',Name='%@',Email='%@',ContactNO='%@',MobileNO='%@',Address='%@'WHERE ID='%@'",UserName.text,Password.text,ConfirmPassword.text, Name.text, Email.text, ContactNO.text, MobileNo.text, Address.text, sqlite3_last_insert_rowid(test1DB)];
  
      const char *insert_stmt = [insertSQL UTF8String];
      sqlite3_prepare_v2(test1DB, insert_stmt, -1, &amp;statement, NULL);
      if(sqlite3_step(statement) == SQLITE_DONE)
      {
          sqlite3_step(statement);
                                  UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"Record added" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                                      [alert show];
                                      [alert release];
                                      alert = nil;    
          sqlite3_finalize(statement);
          sqlite3_close(test1DB);
      }
  
      else {
          sqlite3_step(statement);
                          UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"UIAlertView" message:@"Record notadded" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                          [alert show];
                          [alert release];
                          alert = nil;    
           }
  }
  </code></pre>
  
  <p>}</p>