Problem with Select Command

M

mick.walker

Hi all,
I need some help with a simple select query using MS SQL Server 2005.
The problem I am having is due to the contents of the table, it can
contain names which use punctuation marks such as:

S'Algar
Olhos D'Agua
Praia D'Oura
etc.etc
This is breaking my SQL Queries. I select the data using

Dim command As New SqlCommand("Select * from Navigation where
Keyword='" & Index & "'", connection)
and simply read the data returned by the query, into a dataset.
I'd be grateful for any help offered

Kind Regards
 
K

Karl Seguin [MVP]

Parameterize your queries..it'll be safer and likely fix your bug.

"SELECT * FROM Navigation WHERE Keyword = @Index"
command.Parameters.Add("@Index", SqlDbType.VarChar, 128).Value = index


the VarChar and 128 parts I made up, you'll need to change the to whatever
actual type/length you want.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top