请检查此代码并检查您犯了什么错误。我正在使用此代码,只有这对我有用。
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &adddata) == SQLITE_OK)
{
// NSLog(@"open");
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO contacts(FirstName,LastName,Company,Mobile,Home,Url,Street,City,State,Zip,Prefix,Suffix,Middle,JobTitle,Birthday,Note) VALUES (\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\")", firstName.text,lastName.text,companyName.text,mobileNumber.text,homeNumber.text,homeUrl.text,street.text,city.text,state.text,zip.text,prefix.text,suffix.text,middle.text,jobTitle.text,birthday.text,note.text];
const char *insert_stmt = [insertSQL UTF8String];
int c=sqlite3_prepare_v2(adddata, insert_stmt, -1, &statement, NULL);
NSLog(@"%d",c);
if (sqlite3_step(statement)==SQLITE_DONE)
{
alert=[[UIAlertView alloc]initWithTitle:@"alert" message:@"Data is added" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
[alert show];
NSLog(@"%@",insertSQL);
firstName.text = @"";
}
else
{
alert=[[UIAlertView alloc]initWithTitle:@"alert" message:@"Data is not added" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
[alert show];
}
sqlite3_finalize(statement);
sqlite3_close(adddata);
}