Displaying Multi Language Data on an ASP.NET web page

Handling multi language data is very much important these days; localization of your web page can increase the visitors.

 

 Here in this article I am trying to explain how to deal with the multi language data, here I am trying to explain how you can insert data into SQL Server database and retrieve the data from SQL Server data base and display on the web page.

 

Create a Database namely MultiLangaugeDB and create a table MultiLanguageData

 

USE [MultiLangaugeDB]

GO

/****** Object:  Table [dbo].[MultiLanguageData]    Script Date: 02/19/2009 09:34:36 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_PADDING ON

GO

CREATE TABLE [dbo].[MultiLanguageData](

            [Title] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

            [Description] [binary](1000) NULL

) ON [PRIMARY]

GO

SET ANSI_PADDING OFF

 

To insert data into this table we need write a stored procedure, why because if you try to insert data directly from web page, then you will loose the data while creating a SQL insert statement, so we create a stored procedure to insert data, create following stored procedure in the MultiLangaugeDB

 

USE [MultiLangaugeDB]

GO

/****** Object:  StoredProcedure [dbo].[InsertMultiLanguageData]    Script Date: 02/19/2009 09:36:58 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

 

CREATE PROCEDURE [dbo].[InsertMultiLanguageData]

            – Add the parameters for the stored procedure here

            @Title nvarchar(50),

            @Desc binary(1000)

AS

BEGIN

            SET NOCOUNT ON;

            Insert into MultiLanguageData Values (@Title, @Desc)

END

 

Now we are ready with back end stuff, now lets go and create a web page to insert data.

Create a new web application

On the Default.aspx page add 2 text boxes with and 2 buttons

Fist text box will be used for Title and second text box is used to enter actual multi language data

Name the Button Insert, Displays respectively

Double click on Insert button in the design and add following code in code behind

insert 

 

Here we need to understand the we are converting data into bytes and storing into data base that is why we are have taken our Decription Field in the database table as binary, so that our data will not be lost

 

Now to diplay we need to convert binary data back into string format, that will be using Encoding.Unicode.GetString this will take binary data and convert that data into perticualar language data

 

Just doule click on diplay button in design and add following code in code behind

display 

Now we are ready with our program, just Build, Run and Test

output

Hope this Helps

 

SatishKumar J

MVP (ASP.NET)

Leave a Reply

Powered by WP Hashcash