1

I'm pretty new to the world of Databases. And I'm trying to fill a local database with my local music library. Here's what the table looks like (the string I used to create it)

string sql = ("CREATE TABLE music (searchpaths VARCHAR(20), artists VARCHAR(20), album VARCHAR(20), track VARCHAR(20), year INT, duration INT, tracknumber INT)");

But I'm getting this error (see title of question) when trying to fill the database.

I always seem to get it on the same song. Here's what that "INSERT" string looks like:

"INSERT INTO music (searchpaths, artists, album, track, year, duration, tracknumber) values ('E:\\Music\\01 I Don't Deserve You (Seven Lions Remix) [Radio Edit].mp3', 'Paul van Dyk', 'I Don't Deserve You Remixes', 'I Don't Deserve You (Seven Lions Remix) [Radio Edit]', 2012, 226, 7)"

If there's any more info you need, please tell me. Thanks

2
  • 2
    You have ' in your file name (and other fields too). It denotes end of SQL string. Escape it. Moreover you don't need to escape backslash. Don't you want to care about these stuff? Use parameters. Commented Jan 4, 2014 at 19:15
  • Ah!! Thanks! The backslashes seem to do that on their own, I don't know why, but it still works.. :P Is there any page where you can see the characters which you can't use in a string for SQL? That'd be great. :) Commented Jan 4, 2014 at 19:18

1 Answer 1

1

Since your content also contains single quotes, it's getting jammed up. You can do '' two quotes to escape words like don't.

Though the better answer is to use queries with parameters instead of raw SQL strings.

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

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.