Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Some chars are not accepted by SQL

Posted on 2001-06-28
5
Medium Priority
?
247 Views
Last Modified: 2010-08-05
In my web project I have a large note field that should accept comments by the user. But I have found that some characters will not be accepted by SQL - one of those is the appostrophe "'". I also use a simple encryption routine that produces a lot of non-printable characters as the output and they too are sometimes rejected by SQL. I would think a text field should accept anything, but not true. My note field is very important and I cant limit what the user types in. How do a get around this problem?
0
Comment
Question by:rblackwell
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6234897
It will accept ' but in the query you have to send '' instead.

text field only accepts ascii characters - if you want it to accept characters that are not within that codeset you need to store as unicode and define the field as ntext.
You also need to deal with unicode values in this feld whenever it is accesed or the data transferred.
0
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6234919
e.g.

insert tbl select 'gfhkf'gfhkg'

will fail

insert tbl select 'gfhkf''gfhkg'
will work.

For unicode try

select 'n'
and select N'n'
where n is the char in question. If it is a character set problem then the first one will translate the char.

0
 

Author Comment

by:rblackwell
ID: 6235006
Ok, this seems to make sense. Currently my PW field is set to nvarchar and it only accepts certain charaters. I changed it to ntext and my code would not authenticate anyone with any name, but as soon as I changed the field from ntext back to nvarchar the PW work (but still had the limitation). ??? Should I do something different in my code if the field is ntext? Sorry but i'm just a little confused by your second paragraph.
thanks
0
 
LVL 18

Accepted Solution

by:
nigelrivett earned 400 total points
ID: 6235109
What is the field supposed to hold - you only need ntext if the field needs to be more than 4000 chars.
text fields are a lot more difficult to manipulate than chars so should only be used if necessary.

The nvarchar field will accept any unicode character - if it is not then there is probably a problem with your interface. The field needs to be handled as unicode everywhere.

My last paragraph was pointing out that

insert nvarcharfield select 'ghjk'
will translate any non ascii characters whereas
insert nvarcharfield select N'ghjk'
will retain them
0
 

Author Comment

by:rblackwell
ID: 6239527
You pointed my in the correct direction. I found my com object was casting the incoming variables as Strings which of course do not hold Unicode inforation. Thanks for the lead.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question