1

I am working with Sqlite Database.

In my database

I have some filed Like, Invoice,Name,Date

My Invoiceno datatype is INTEGER,

In Select query Got output like this.

 Query:(
    {
     InvoiceNo = 1;
     Name : ABC
     Date = "2012-04-16 00:00:00";

    }
  )

But when try to Get that Invoice no to string it's given Diff. Value.

Code for getting invoice from array to String:

  NSString *str = [NSString stringWithFormat:@"%i",[[Query objectAtIndex:indexPath.row] valueForKey:@"InvoiceNo"]];
    NSLog(@"str:%@",str);

Here, My invoice no is 1, & It's give me a value "2387056"

Please, Help me..How can i solve this problem?

4
  • [NSString stringWithFormat:@"%d",[[Query objectAtIndex:indexPath.row] valueForKey:@"InvoiceNo"]]; maybe it will help you. Commented Apr 16, 2012 at 13:06
  • 1
    %d and %i should result with a 32bit int Commented Apr 16, 2012 at 13:07
  • @chinttu Thanks for Answer,it's given me other string value... Commented Apr 16, 2012 at 13:08
  • 1
    @Anki you have to do %d or doin typecast "intValue" .. maybe it will help. u got answer? Commented Apr 16, 2012 at 13:10

2 Answers 2

2
NSString *str = [NSString stringWithFormat:@"%i",[[Query objectAtIndex:indexPath.row] valueForKey:@"InvoiceNo"]];
    NSLog(@"str:%@",str);
you have to replace above lines with below lines

NSString *str = [NSString stringWithFormat:@"%i",[[[Query objectAtIndex:indexPath.row] valueForKey:@"InvoiceNo"] intValue]];
    NSLog(@"str:%@",str);
Sign up to request clarification or add additional context in comments.

Comments

1

Convert NSString to int

NSString *values = @"1";

int yourValue = [values intValue];

NSLog(@"Int Value : %d",yourValue);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.