Saving multilingual text inside SQL Server by M. Vadivel

 

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 15
September 17, 2002
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

Saving multilingual text inside SQL Server

Advantages:

In most of the sites you would have seen the user downloading a type of font and installing it in their Windows à fonts folder. The users will be able to see the characters of that particular language only after this downloading is done. But if you as the site developer save the Unicode text that represents a language inside a table and display that content in the web page then there is no need of user downloading the font. Isn’t this a great advantage? (For ex: If you are creating a web page in Chinese language then the user would be forced to download some font files which would be approx 6MB.)

Disadvantage:

If you like to offer multiple language support to users of your website, it is most important to use the Unicode character strings, nchar, nvarchar, and ntext (where n stands for “National”), for all character data but the sad part is that it would take more storage space than the character strings.

A small example Web page 1

Create an html page from where you can copy multilingual text from any site and paste it in a provision given in this page. Please note that I am not concentrating on any client side validations here. So it is your responsibility to add any client side validation according to your needs.

<Html>
<Head>
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<Title>Saving Multilingual character into database</Title>
</Head> <Body>
<h3 align="center">Copy multilingual text from any site and paste it inside this textbox before pressing the submit button</h3> <form name="frmInputDB" method="post" action="frmSaveandRetrieve.asp"> <table border=1 align="center"> <tr> <td>Enter your text here :</td> <td><input name="txtMultiLingual"></td></tr> <tr> <td colspan="2" align="center"> <input type=submit name="btnButton" value="Submit"> </td> </tr> </table> <p><p>* Please note that no validation has been done in this page. </form> </Body>
</Html>

Did you note the change in the meta tags charset property? Yes you need to specify “utf-8” as your charset so that Unicode characters would be allowed in that page. If you try skipping that line while creating any multilingual web page you would get an error while saving that page. The error would read something like this “Some Unicode characters in the file cannot be represented in the current code page and were replaced by default character…….”.

Web page 2

<Html>
<Head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
</Head>
<Body>
<%
Dim DBConn,strConnection,sql,
strConnection="---Put your connection string here."
Set DBConn = Server.CreateObject("Adodb.Connection")
set Rs=server.CreateObject("ADODB.Recordset")  
DBConn.Open(strConnection)
Strdescription = Request.Form("txtMultiLingual")
sql = "insert into UniTesting(description) values(N'" & Strdescription & "')"
dbConn.Execute(sql)
sql = "select id, [description] from UniTesting order by id"
set Rs=dbConn.execute(sql)%>
<table border=1>
<tr>
<td>Row Id</td>
<td>Multi-Lingual Text</td>
</tr>
<%
while not rs.EOFResponse.Write ("<tr><td>")Response.Write Rs("id") & "</td><td>" & Rs(1) & "</td><tr>"rs.MoveNextwend%></table></Body>
</Html>

If you try to insert data in some language, which isn’t the default language of the OS or SQL Server, then all the characters inserted into the database might be substituted. Since SQL Server 7.0 and 2000 support both Unicode and non-Unicode data types, they require you to use the "N" prefix in front of Unicode string literals (before the open quotes). Just remember: simply place that "N" prefix in front of the string literal you are using. This will allow your data to be inserted without being corrupted, and this would also be a faster process!

A small DB structure

CREATE TABLE UniTesting (id int IDENTITY (1, 1) NOT NULL , 
description nchar (100) NULL)
blog comments powered by Disqus
DATABASE CODE ARTICLES

- Deployment of the MobiLink Synchronization M...
- MobiLink Synchronization Wizard in SQL Anywh...
- Finding Matching Records in Data Access Pages
- Using the AccessDataSource Control in VS 2005
- A Closer Look at ADO.NET: The Command Object
- A Closer Look at ADO.NET: The Connection Obj...
- Using ADO to Communicate with the Database, ...
- Code Snippets: Counting Records
- Constraints In Microsoft SQL Server 2000
- Multilingual entries into a DB and to be dis...
- Two combos, one textbox example
- ADO Recordset Paging
- SQL Server Database Creator - .NET Version
- Getting A List of Tables From SQL Server
- Discussion & Listserv Module by Mike Eck...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials