Skip to main content

Posts

Showing posts with the label CKEditor

SQL Server - Multi language data support

Problem:

I used CKEditor to edit my pages. Then, I stored the content of the pages to SQL Server 2008 database. The page contents should support in different languages such as English, German and Vietnamese. I met a problem when I worked on Vietnamese pages.
The text was successfully saved but it was displayed wrong when reading again from database, likes the following:
Input: "Ðây là Tiếng Việt"
Display: "Ðây là Ti?ng Vi?t".

Solution:

We need to use nvarchar (nchar | ntext) data type for strings  and we also need to precede all unicode strings with 'N'

Here is my code:
--create table CREATE TABLE [dbo].[xedu_page_content]( [id] [numeric](11, 0) IDENTITY(1,1) NOT NULL, [category] [varchar](100) NOT NULL PRIMARY KEY, [content] [Ntext] NULL ) --save BEGIN TRAN IF not exists (SELECT category FROM xedu_page_content WHERE category='"+in.categoryKey+"') INSERT INTO xedu_page_content(category,content) VALUES ('"+i…