Friday, January 27, 2012

' Question throwing exception

I have a comboBox with some names binded to it....With in the names some of them are like Store's Store, and like Danny's Gym...when i select names with ' in them i get this exception

Incorrect Syntax near 'S' Unclosed Question mark before the charectar string ORDER BY "SomeValue".....how could i go about fixing this?

should i include some king of function that pulls out those quotes? or what? any help with this issue

there are two properties of combobox that can be bound

selected value and the displaymember. you must bound selected value to the pk and use it

instead of the text with the quote problem

going back to the quote problem you might want to check this queries out

USE NORTHWIND
select 'that''s all folks' that's a double single quote

INSERT INTO CUSTOMERS(customerid,companyname, contactname)
values('SOXCL','THE SICK O''CLOCK', 'Jack O''donell')

select * from customers where companyname='THE SICK O''CLOCK'

delete from customers where customerid ='soxcl'

|||

You need to double up quotes in your strings, like changing:

'Danny's'

to

'Danny''s'

This is understood to be a single quote in the string. You should also figure some way to see the string being used for a query like this. If you saw the query:

select column from table where column like 'denny's' it would be obvious what the problem was.

No comments:

Post a Comment