Solved

Some chars are not accepted by SQL

Posted on 2001-06-28
5
235 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 100 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

948 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now