0

在这里,我将记录静态插入数据库。我的问题是我想将 tableview 中的重新编码添加到 sqlitedatabase 中。

-(IBAction)favouriteButtonClick
{
    NSArray *dirArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docPath = [dirArray objectAtIndex:0];
    databasePath = [docPath stringByAppendingPathComponent:@"favouritecontact"];
    NSLog(@"Database path=>%@",databasePath);

    sqlite3_stmt *statement;
    const char *dbpath=[databasePath UTF8String];

    if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
    {
        //NSString *insertSQL=[NSString stringWithFormat:@"INSERT INTO favourite(FirstName,LastName,FullName,HomeEmail,HomeEmail,WorkEmail,MobileNo)VALUES(\"%@\", \"%@\", \"%@\",\"%@\",\"%@\", \"%@\")",FirstName.text,LastName.text,FullName.text,HomeEmail.text,WorkEmail.text,MobileNo.text];

         NSString *insertSQL=[NSString stringWithFormat:@"INSERT INTO favourite(FirstName,LastName,FullName,HomeEmail,WorkEmail,MobileNo)VALUES('ketan','yadav','ketanyadav', 'ky@gmail.com','ketanyadav@gmail.com','1122334455')"];

         NSLog(@"insertsql%@",insertSQL);

         const char *insert_stmt=[insertSQL UTF8String];

         sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL);
         sqlite3_step(statement);
         sqlite3_finalize(statement);
         sqlite3_close(contactDB);
         NSLog(@"Record add to database");
    }
}
4

2 回答 2

0

you can find answer at below link:

http://www.techotopia.com/index.php/An_Example_SQLite_based_iPhone_Application

Here in this Example, there is a TextField, so it Saves Textfield's data, In your case you have to set value of your particular cell [of particular field]

于 2013-06-06T10:15:11.140 回答
0

当用户点击“收藏夹”按钮时,听起来您想要识别 TableView 中当前选定的行。那正确吗?

这将为您提供当前选择的索引:

NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow];

如果您的 TableView 中只有一个部分,那么[selectedIndexPath row]将为您提供要在联系人数组中查找的行号——或者无论您的数据源是什么。

于 2013-06-06T11:23:30.690 回答