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 8501501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:13:48+00:00 2026-06-11T01:13:48+00:00

I am trying to insert data into a database but I have it seems

  • 0

I am trying to insert data into a database but I have it seems like it won’t insert integer values, it is inputing strings. the app just crashes.

if I push the button that saves it into the database, with the textfields empty, the methods does insert data into the database, but with 0 values, so the method works.

the method I use is:

-(BOOL) insertIntoDatabase: (NSInteger)day: (NSInteger)month:(NSInteger)year:(NSInteger)hours:(NSInteger)minutes:(NSInteger)salary:(NSString *)extra
{
    FMDatabase *dbHandler = [FMDatabase databaseWithPath: [Utility getDatabasePath]];
    BOOL success;
    @try {
        [dbHandler open];

        success =  [dbHandler executeUpdate:@"INSERT INTO inputs (day, month, year, hours, minutes, salary, extra) VALUES (?,?,?,?,?,?,?);",
                         day, month, year, hours, minutes, salary, extra];

        [dbHandler close];
    }
    @catch (NSException *exception) {
        NSLog(@"error..");
    }
    @finally {
        return success;
    }
}

And this is the method I call from my viewController class

-(IBAction)enterToDatabase:(id)sender{

    InputClassDatabaseHandler *databaseMethods = [[InputClassDatabaseHandler alloc]init];
    BOOL accept;

    NSInteger day = [_day.text integerValue];
    NSInteger month= [_month.text integerValue];
    NSInteger year= [_year.text integerValue];
    NSInteger hours= [_hours.text integerValue];
    NSInteger minutes= [_minutes.text integerValue];
    NSInteger salary= [_salary.text integerValue];

    //hardcoded for testing...
    NSString *extraWork = @"No";

    accept = [databaseMethods insertIntoDatabase:day :month :year :hours :minutes :salary :extraWork ];
}
  • 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-11T01:13:50+00:00Added an answer on June 11, 2026 at 1:13 am

    Always remember to pass any arguments to SQL query as an object. NSInteger in not an object, so put it in NSNumber object and it will work fine.

    This should work for you:

    -(BOOL) insertIntoDatabase: (NSInteger)day: (NSInteger)month:(NSInteger)year:
    (NSInteger)hours:(NSInteger)minutes:(NSInteger)salary:(NSString *)extra
    {
    
     FMDatabase *dbHandler = [FMDatabase databaseWithPath: [Utility getDatabasePath]];
     BOOL success = NO;
     if(![db open])
     {
       NSLog(@"Error");
       return NO;
     }
     [dbHandler beginTransaction];
     success =  [dbHandler executeUpdate:@"INSERT INTO inputs (day, month, year, hours, minutes, salary, extra) VALUES (?,?,?,?,?,?,?);",
                         [NSNumber numberWithInt:day], [NSNumber numberWithInt:month], 
                         [NSNumber numberWithInt:year], [NSNumber numberWithInt:hours],  
                         [NSNumber numberWithInt:minutes], [NSNumber numberWithInt:salary],          
                         [NSNumber numberWithInt:extra] ];
    
        [dbHandler commit];
        [dbHandler close];
    
     return success;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert some data into a pysqlite database but even tho
I'm trying to insert data into the SQLite database using get EditText, but I
I am trying to insert data into my SQLite database. I have imported all
Hi I am trying insert data into the database using prepared statement but I
I'm trying to insert some data into mysql database, but I get an error
I'm trying to insert some binary data into database using 'mysql' gem in ruby.
Getting a strange error when trying to insert data into an Access database using
I am trying to insert data from a database into a textarea. I can't
I have a form that is trying to insert some data into an SQL
I'm trying to insert some data from a proprietary JSON database into MongoDB for

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.