1

I am working on iPhone app. I have the SQL query:

 NSString *myRed = [NSString stringWithFormat: @"%1.4f", slideR.value];

 [self insertData:@"INSERT INTO colour VALUES("+myRed+")"];

It produces syntax error. How to insert a string into string. That approach in Java would have worked. Best regards

2 Answers 2

1

Try this :

NSString *myRed = [NSString stringWithFormat: @"%1.4f", slideR.value];

[self insertData:[NSString stringWithFormat:@"INSERT INTO colour VALUES(\"%@\")",myRed]];

If you don't want " then :-

[self insertData:[NSString stringWithFormat:@"INSERT INTO colour VALUES(%@)",myRed]];

Hope it helps you.

Sign up to request clarification or add additional context in comments.

Comments

1

You could try writing your query and your string appended together before hand.

             NSString *str = @"Your values";
             NSString *query = [NSString stringWithFormat:@"INSERT INTO color VALUES(%@)", str];
             [self insertData:query];

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.