-1

I am making an application where i want to use update query?

In my application i have two stages to complete the registration process

in page1 i have registration form and one submit button?

on click of submit button all the details should get insert into my sqlite table.

in page2 i have confirmation page and one edit and continue button?

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?

but i have try doing this but i am not able to update the last enter value?

following is my code page1 insert 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, &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, &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];

            }                   
        }


    }
}

from the above code i am able to get the row id but i am not able to use that rowid in update query

following is my code page2 Update code:

-(IBAction)Update;

{

sqlite3_stmt  *statement;

const char *dbpath = [databasePath UTF8String];

if (sqlite3_open(dbpath, &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, &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;    
     }
}
Ghostman
  • 6,042
  • 9
  • 34
  • 53

1 Answers1

0

Simple Way -> create "someconstant.h" file declare your _rowID variable there.

Import file in your class,assign your value in first class and used it in second class.

mandeep-dhiman
  • 2,505
  • 2
  • 21
  • 31
  • i don't want to create any new page for this.... want i am try to explain is .....i am getting last_insert_rowid on page1 were i am using insert query.....but now i want to use that rowid value in other page and want to fire update query..... and i want to do this stuff jst once so no need of greating a new page to store the varibale..........so please help out – Vinod Vishwakarma Nov 04 '11 at 11:21