1

I have problem in C# to make a SQLite command. I've trying to use code like this:

SQLiteCommand komenda = new SQLiteCommand("SELECT cena FROM dniowka WHERE (model = '@Name' AND element = '@Name2')", cnn);

but it doesn't work... :( before i used LIKE statement:

SQLiteCommand komenda = new SQLiteCommand("SELECT cena FROM dniowka WHERE model LIKE @Name AND element LIKE @Name2", cnn);

it works. But I have a little problem. When I have a few records that contain "AL" for example, "1AL, 2AL, AL ...". I do not know how to do to get the only one record "AL" (@ Name2 = AL).

Does anyone have any idea?

[P. S. sorry for my english ..]

2 Answers 2

2

instead of LIKE you can use =

e.g.

"SELECT cena FROM dniowka WHERE model = @Name AND element = @Name2"

Note that I didn't include single quotes:

'@Name' <-- BAD

@Name <-- GOOD

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

Comments

1

Because you don't need to use apostrof when you using parameterized queries.

Use parameters in your query like model = @Name not model = '@Name'

The right usage of this;

SQLiteCommand komenda = new SQLiteCommand("SELECT cena FROM dniowka 
                            WHERE model = @Name 
                            AND element = @Name2", cnn);

komenda.Parameters.AddWithValue("@Name", Name);
komenda.Parameters.AddWithValue("@Name2", Name2);

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.