473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Cannot insert certain characters in SQL Server

Hi everyone,

Recently I have posted a question regarding special characters in text
files. I was trying to read the text file to process the text later on, but
I was using the wrong encoding. The correct encoding turned out to be
extended ASCII (850).

But now I'd like to store the result in a database. I have tried to do this
by just issueing an insert statement, using the following piece of code:
SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
int result = cmd.ExecuteNonQuery();

This works, but now I'm faced with the same problem, only in reverse - ni
the database, the characters are stored in the wrong encoding!

Is there a way to specify the encoding in which I would like to safe the
characters in the database? What do I need to change in the code?

Thanks in advance,

JayCee
--
http://jcsnippets.atspace.com
a collection of source code, tips and tricks
May 10 '06 #1
4 5445
If you change the field to a Unicode field, e.g. ntext or nvarchar, it
can handle the characters without problem.

jcsnippets.atspace.com wrote:
Hi everyone,

Recently I have posted a question regarding special characters in text
files. I was trying to read the text file to process the text later on, but
I was using the wrong encoding. The correct encoding turned out to be
extended ASCII (850).

But now I'd like to store the result in a database. I have tried to do this
by just issueing an insert statement, using the following piece of code:
SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
int result = cmd.ExecuteNonQuery();

This works, but now I'm faced with the same problem, only in reverse - ni
the database, the characters are stored in the wrong encoding!

Is there a way to specify the encoding in which I would like to safe the
characters in the database? What do I need to change in the code?

Thanks in advance,

JayCee

May 10 '06 #2
Göran Andersson <gu***@guffa.com> wrote in
news:#Y**************@TK2MSFTNGP04.phx.gbl:
If you change the field to a Unicode field, e.g. ntext or nvarchar, it
can handle the characters without problem.


Alas, the field I'm using already is nvarchar.

If I print the insert statement to the console window prior to passing it
to the database, the characters are correct. After the insert, they no
longer appear correct in the database (nor in the application that uses
said database).

Thanks,

JayCee
--
http://jcsnippets.atspace.com
a collection of source code, tips and tricks
May 10 '06 #3
What do you use to insert the record? If you build the SQL query
yourself, remember that you have to put an N in front of a string
constant to make it Unicode.

jcsnippets.atspace.com wrote:
Göran Andersson <gu***@guffa.com> wrote in
news:#Y**************@TK2MSFTNGP04.phx.gbl:
If you change the field to a Unicode field, e.g. ntext or nvarchar, it
can handle the characters without problem.


Alas, the field I'm using already is nvarchar.

If I print the insert statement to the console window prior to passing it
to the database, the characters are correct. After the insert, they no
longer appear correct in the database (nor in the application that uses
said database).

Thanks,

JayCee

May 10 '06 #4
Göran Andersson <gu***@guffa.com> wrote in
news:OK**************@TK2MSFTNGP04.phx.gbl:
What do you use to insert the record? If you build the SQL query
yourself, remember that you have to put an N in front of a string
constant to make it Unicode.


Ah, I was not aware of that. I'm indeed building the SQL query myself, and
now that the N is in front of each String constant, the result in the
database looks fine.

Thank you very much!

Best regards,

JayCee
--
http://jcsnippets.atspace.com
a collection of source code, tips and tricks
May 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: edmondlch | last post by:
I am using a VB 6.0 application programs to insert some chinese traditional characters into the MS SQL Server 6.5 database. It is normal when the application running in the server locally. However,...
2
by: hartley_aaron | last post by:
Hi, I have an application running on a wireless device and being wireless I want it to use bandwidth as efficiently as possible. Therefore, I want the SQL statement that it uploads to the SQL...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
4
by: anony | last post by:
Hi, I'm looking to find out how to properly handle the input of certain characters into a textbox that will be inserted into a database. In this app, text is copied and pasted into a textbox...
3
by: teddysnips | last post by:
I need a trigger (well, I don't *need* one, but it would be optimal!) but I can't get it to work because it references ntext fields. Is there any alternative? I could write it in laborious code...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
0
by: kennymce | last post by:
Hi, I'm having trouble localizing my Oracle 9.2 / ASP web application for our Chinese-speaking users. My Oracle 9.2 Database has NLS_NCHAR_CHARACTERSET set to AL16UTF16. I've set up a test...
6
by: AG | last post by:
ASP.NET 2.0 aspx page with a FormView bound to an ObjectDataSource to view, add and edit records. Can anyone point me to a sample of how to retain the user entered control values when an insert...
5
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration:...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.