Rey_mysterio
Rey_mysterio

Reputation: 81

how to insert a db in sqlite3? shows error

I'm trying to insert my data into db.db created successfully but data not insert into the database.but the data successfully goes to insertsql after that showing error.pls check my code

-(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];

}

Upvotes: 0

Views: 158

Answers (1)

Stephen Darlington
Stephen Darlington

Reputation: 52575

You say that the error message returned is:

Failed to update row no such table: STABLE

And, well, the problem is exactly that: there is no table called STABLE. You've clearly managed to connect to a database but there is no table there with the name that you expect.

The real question is how and when did you create the table? Chances are the database you're connected to is not the one you think is being used.

Upvotes: 1

Related Questions