Click here to Skip to main content
12,072,456 members (52,903 online)
Rate this:
 
Please Sign up or sign in to vote.
-(BOOL) updatedata:(NSString*)name mobileno:(NSString*)mobileno
email:(NSString*)email gender:(NSString*)gender address1:(NSString*)address1 address2:(NSString*)address2 city:(NSString*)city state:(NSString*)state country:(NSString*)country pincode:(NSString*)pincode dob:(NSString*)dob
{
// trying new
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{

const char *sqlQuery = "UPDATE studentsDetail SET name = ?,mobileno = ?,email = ?,gender = ?,address1 = ?,address2 = ?,city = ?,state = ?,country = ?,pincode = ?,dob = ? WHERE name == ?";

sqlite3_stmt *query = nil;

int retVal;
if ((retVal = sqlite3_prepare_v2(database, sqlQuery, -1, &query, NULL)) == SQLITE_OK) {
sqlite3_bind_text(query, 1, [name UTF8String], -1, SQLITE_TRANSIENT );
sqlite3_bind_text(query, 2, [mobileno UTF8String], -1, SQLITE_TRANSIENT );
sqlite3_bind_text(query, 3, [email UTF8String], -1, SQLITE_TRANSIENT );
sqlite3_bind_text(query, 4, [gender UTF8String], -1, SQLITE_TRANSIENT );
sqlite3_bind_text(query, 5, [address1 UTF8String], -1, SQLITE_TRANSIENT );
sqlite3_bind_text(query, 6, [address2 UTF8String], -1, SQLITE_TRANSIENT );
sqlite3_bind_text(query, 7, [city UTF8String], -1, SQLITE_TRANSIENT );
sqlite3_bind_text(query, 8, [state UTF8String], -1, SQLITE_TRANSIENT );
sqlite3_bind_text(query, 9, [country UTF8String], -1, SQLITE_TRANSIENT );
sqlite3_bind_text(query, 10, [pincode UTF8String], -1, SQLITE_TRANSIENT );
sqlite3_bind_text(query, 11, [dob UTF8String], -1, SQLITE_TRANSIENT );
sqlite3_bind_text(query, 12, [name UTF8String], -1, SQLITE_TRANSIENT );

int result;
if ((result =sqlite3_step(query)) != SQLITE_DONE) {
NSLog(@"Failed to execute the query %d",result);
}
else {
NSLog(@"Succesfully updated row !");
}
sqlite3_reset(query);
sqlite3_finalize(query);
}
else {
NSLog(@ "Error in preparing UPDATE statement %d",retVal);
}
int result1 = sqlite3_close(database);
if (result1 != SQLITE_OK){
NSLog(@"Failure in closing connection to database. Result %d",result1);
}
else {
NSLog(@ "Successfully closed DB connection ") ;
}
}
return YES;
}

i am getting an error as:
"Failed to execute the query 5"
which line of the code is wrong in it....
Posted 5-Jun-13 3:39am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I think your "where" clause is incorrect, it should be "where name = ?" instead of ==.
  Permalink  
Comments
SanjeevJayaram 6-Jun-13 0:49am
   
i tried single = in where clause but still the same error occurs.

"Failed to execute the query 5"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 5 Jun 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100