【发布时间】:2017-08-12 20:45:13
【问题描述】:
我正在尝试插入 2 个文本框的值,即用户 ID 和密码。 但我没有收到任何错误或异常。
代码如下:
我已经拿了两本教科书,点击那个按钮就可以完成。
这是我的 .m 文件:
#import "ViewController.h"
#import "sqlite3.h"
#import <CommonCrypto/CommonCryptor.h>
NSString *databasePath;
NSString *docsDir;
static sqlite3 *database = nil;
static sqlite3_stmt *statement = nil;
@interface ViewController ()
@end
@implementation ViewController
@synthesize status,status2;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)saveData:(id)sender{
databasePath = [[NSBundle mainBundle]pathForResource:@"ButterFly2BE" ofType:@"db"];
NSString *p=@"PAss";
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &adddata) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat:
@"INSERT INTO tblUser (UserId,Password,Description) VALUES(\"%@\",\"%@\",\"%@\")"
, _username.text, _password.text, p];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(adddata, insert_stmt,-1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
status.text = @"Contact added";
// status.text = @"";
status2.text = @"";
// phone.text = @"";
} else {
status.text = @"Failed to add contact";
}
sqlite3_finalize(statement);
sqlite3_close(adddata);
}
}
@end
【问题讨论】:
-
您遇到了什么问题?数据没有插入……对吧?只需记录 sql 查询并使用 DB browser for SQLite 打开数据库。
-
参考这个链接你会找到答案stackoverflow.com/questions/17080018/…
标签: ios objective-c iphone ios10