Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8546427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:01:08+00:00 2026-06-11T13:01:08+00:00

I tried to insert values in sqlite3 database, but it cant work on my

  • 0

I tried to insert values in sqlite3 database, but it cant work on my app.
I follow this code where all this values in table are varchar.

sqlite3_stmt *statement;

NSString *docsDir;
NSArray *dirPaths;
int ID;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

docsDir = [dirPaths objectAtIndex:0];

// Build the path to the database file
databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"weather.sqlite"]];


const char *dbpath = [databasePath UTF8String];

if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
    NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO satish VALUES ('jodhpur','hazy1','68','7','700','30','28','10sept')"];

    const char *insert_stmt = [insertSQL UTF8String];

    sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL);
    {
        NSLog(@"%@",statement);
        sqlite3_bind_text(statement, 1, insert_stmt, -1, SQLITE_TRANSIENT );

        if (sqlite3_step(statement) == SQLITE_ROW)
        {
            ID = sqlite3_last_insert_rowid(contactDB);

            NSLog(@"Data inserted successfully ");

        } 
        else{             
            NSLog(@"Failed to add contact");
        }
    }
    sqlite3_finalize(statement);
    sqlite3_close(contactDB);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:01:10+00:00Added an answer on June 11, 2026 at 1:01 pm
    //tyr this code    
    // you must give the column name to insert values in DB   
    
         NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
                NSString *documentsDir = [paths objectAtIndex:0];
    
                NSFileManager *fileManager = [NSFileManager defaultManager];
                NSError *error;
                NSString *dbPath =[documentsDir stringByAppendingPathComponent:@"register.sqlite"];
                BOOL success = [fileManager fileExistsAtPath:dbPath]; 
                sqlite3_stmt *selectstmt;
                if(!success)
                {
                    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"register.sqlite"];
                    success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
    
                    if (!success) 
                        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
                }
    
                if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
                    //*************** insert value in database******************************\\ 
    
                    const char *sql = "insert into satish (firstname,lastname,email,company,phone) VALUES ('sdcbb','bbbb','bbbb','bbbb',1111122)";
                    sqlite3_prepare_v2(database,sql, -1, &selectstmt, NULL); 
                    if(sqlite3_step(selectstmt)==SQLITE_DONE)
                    {
                        NSLog(@"insert successfully");
                    }
                    else
                    {
                        NSLog(@"insert not successfully");
    
                    }
                sqlite3_finalize(selectstmt);
                    sqlite3_close(database);
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application I created a database and I tried to insert values into
Using prepared statement i tried to insert values into table shows No column name
I tried to insert a base64 encoded string into my SQLite database, but when
I tried to create a single insert query for the values in template_list array.
I tried to insert a set of rows as soon as a table is
How to insert html code inside an array in PHP? I tried searching on
I'm making Android app that has this database in it: public void onCreate(SQLiteDatabase db)
I insert data into sqlite database table and when i insert first record ,
I'm using the Ruby Sqlite3 library to insert some records into a database. I'm
I wrote the database schema (only one table so far), and the INSERT statements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.