Solved

Some chars are not accepted by SQL

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

744 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

9 Experts available now in Live!

Get 1:1 Help Now