Priyankadmehta
iPF Noob
I am ipad application developer and i want to insert data from my app to sqlite database in my application i have one registration form view controller class in that there are different textfield and value in the textfield and i want to insert that textfield value in existing table of sqlite database file
i have tried following code but it doesn't work
My code is:
#define sqLiteDb [[NSBundle mainBundle] pathForResource"eureka_latest1" ofType"sql"]
if (sqlite3_open([sqLiteDb UTF8String], &_database) != SQLITE_OK) {
NSLog(@"Failed to open database!");
}
sqlite3_stmt *insertStatement;
NSString *query1 = [NSString stringWithFormat"INSERT INTO student (Fname, Mname) VALUES (\"%@\", \"%@\")",textfname.text,textmname.text];
char *error;
if ( sqlite3_exec(_database, [query1 UTF8String], NULL, NULL, &error) == SQLITE_OK)
{
NSLog(@"Data inserted.");
sqlite3_bind_text(insertStatement, 1, [textfname.text UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(insertStatement, 2, [textmname.text UTF8String], -1, SQLITE_TRANSIENT);
}
else
{
NSLog(@"Error: %s", error);
}
sqlite3_finalize(insertStatement);
sqlite3_close(_database);
}
i have tried following code but it doesn't work
My code is:
#define sqLiteDb [[NSBundle mainBundle] pathForResource"eureka_latest1" ofType"sql"]
if (sqlite3_open([sqLiteDb UTF8String], &_database) != SQLITE_OK) {
NSLog(@"Failed to open database!");
}
sqlite3_stmt *insertStatement;
NSString *query1 = [NSString stringWithFormat"INSERT INTO student (Fname, Mname) VALUES (\"%@\", \"%@\")",textfname.text,textmname.text];
char *error;
if ( sqlite3_exec(_database, [query1 UTF8String], NULL, NULL, &error) == SQLITE_OK)
{
NSLog(@"Data inserted.");
sqlite3_bind_text(insertStatement, 1, [textfname.text UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(insertStatement, 2, [textmname.text UTF8String], -1, SQLITE_TRANSIENT);
}
else
{
NSLog(@"Error: %s", error);
}
sqlite3_finalize(insertStatement);
sqlite3_close(_database);
}