Click here to Skip to main content
13,092,310 members (64,991 online)
Rate this:
Please Sign up or sign in to vote.
sqlite3 *database;
sqlite3_stmt *compiledStmt;
// Init the animals Array
NSString *docsDir;
NSArray *dirPaths;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
// Build the path to the database file
databasePath = [[NSString alloc] initWithString:
[docsDir stringByAppendingPathComponent:student.db]];

// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)

NSString *insertSQL=insert into studentsDetail(image) values(?);
if (sqlite3_prepare_v2(database, [insertSQL cStringUsingEncoding:NSUTF8StringEncoding], -1, &compiledStmt, NULL)== SQLITE_OK)
UIImage *image = [UIImage imageNamed:@"Cameroon.png"];
NSData *imageData=UIImagePNGRepresentation(image);

sqlite3_bind_blob(compiledStmt, 1, [imageData bytes], [imageData length], SQLITE_TRANSIENT);
if(sqlite3_step(compiledStmt) != SQLITE_DONE ) {
NSLog( @"Error: %s", sqlite3_errmsg(database) );
} else {
NSLog( @"Insert into row id = %lld", (sqlite3_last_insert_rowid(database)));


what is wrong in the code...
Posted 4-Jun-13 1:50am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Debug your code and find what exactly the problem is?

At least get the error so some can help you move on.

Also check this CP article on same:
C# & SQLite - Storing Images[^]

..and similar answer here[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 4 Jun 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100