What's new
Apple iPad Forum 🍎

Welcome to the Apple iPad Forum, your one stop source for all things iPad. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Insert data from textfield to sqlite database

Priyankadmehta

iPF Noob
Joined
Mar 5, 2012
Messages
7
Reaction score
0
Location
Ahmedabad
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:mad:"eureka_latest1" ofType:mad:"sql"]
if (sqlite3_open([sqLiteDb UTF8String], &_database) != SQLITE_OK) {
NSLog(@"Failed to open database!");
}
sqlite3_stmt *insertStatement;
NSString *query1 = [NSString stringWithFormat:mad:"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);
}
 

Most reactions

Latest posts

Top