Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在sqlite3中插入db?显示错误_Objective C_Ios_Database_Ios5 - Fatal编程技术网

Objective c 如何在sqlite3中插入db?显示错误

Objective c 如何在sqlite3中插入db?显示错误,objective-c,ios,database,ios5,Objective C,Ios,Database,Ios5,我正在尝试将我的数据插入数据库。数据库创建成功,但数据未插入数据库。但数据在显示错误后成功进入insertsql。请检查我的代码 -(void)insertDB { NSString *dname=[[NSString alloc]init]; dname=[delegate.Name objectAtIndex:0]; sqlite3_stmt *statement; const char *dbpath=[delegate.databasepath UTF8String]; if (sq

我正在尝试将我的数据插入数据库。数据库创建成功,但数据未插入数据库。但数据在显示错误后成功进入insertsql。请检查我的代码

-(void)insertDB
{
NSString *dname=[[NSString alloc]init];
dname=[delegate.Name objectAtIndex:0];

sqlite3_stmt *statement;
const char *dbpath=[delegate.databasepath UTF8String];

if (sqlite3_open(dbpath, &contactDB)==SQLITE_OK)
{

    NSString *insertSQL=[NSString stringWithFormat:@"INSERT INTO STABLE (NAME) VALUES (\"%@\")",dname];

    //insert sql is ok,after that they shows error

    const char *insert_stmt=[insertSQL UTF8String];

    NSLog(@"const char%@",insert_stmt);

    sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement,NULL);

    if (sqlite3_step(statement)==SQLITE_DONE)
    {

        NSLog(@"saved");
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"data" message:@"saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];

        [self counting];
    }
    else
    {
        NSLog(@"Failed to add new favourites");
        NSLog(@"Failed to update row %s", sqlite3_errmsg(contactDB));
    }
    sqlite3_finalize(statement);
    sqlite3_close(contactDB);
}
[self loadmusic];

}

您说返回的错误消息是:

无法更新行没有这样的表:稳定

问题就在于:没有一个表叫做
STABLE
。显然,您已经成功地连接到了数据库,但其中没有具有预期名称的表


真正的问题是如何以及何时创建表?您连接的数据库可能不是您认为正在使用的数据库。

插入数据库插入稳定(名称)值(“音乐”)2012-11-13 01:10:01.369[35050:707]未能添加新收藏夹2012-11-13 01:10:01.371[35050:707]未能更新行没有这样的表:STABLESo您是否创建过表?(您是否阅读过“创建表稳定”(ID INTEGER主键,名称VACHAR(50));(请记住,如果您在“bundle”目录中“创建”DB,它将不会真正存在。它必须在应用程序的一个R/W目录中创建。)