Wednesday, March 7, 2012

How insert Arabic/urdu characters in SQL server

Hi

I am developing an application where i want to store the different language (i.e. chines,Arabic,urdu etc) character in database (SQL Server). so when i store arabic characters in SQL server , it stores the (???).

datatype of field is nvarchar.

is anybody know about the problem and solution.

Regards

Mubahsar Ghazi

The problem is called character conversion and you are getting it because you are using only NVarchar without doing column level collation for Arabic in your database. There are three collations for Arabic in SQL Server 2005. If you are using SQL Server 2000 you can still do column level collation, the links below deals with SQL Server 2005. Hope this helps.

144

binary.256

Binary

SQL_Latin1_General_1256_BIN

145

diction.256

Dictionary order, case-sensitive

SQL_Latin1_General_Cp1256_CS_AS_KI_WI

146

nocase.256

Dictionary order, case-insensitive

SQL_Latin1_General_Cp1256_CI_AS_KI_WI

http://msdn2.microsoft.com/en-us/library/ms144250(SQL.90).aspx

http://msdn2.microsoft.com/en-us/library/ms180175(SQL.90).aspx

|||

thanks for ur response

but i m still getting problems.....

i m pasting the whole code below.while executing it show the exceptionCast from string "?" to type 'Byte' is not valid.

.....................

Dim cAsString = HelpArea.Text ' HelpArea is text box where urdu/arabic characters can be writen

convertC = UniToVar(c) ' function written below

Cmd =

New SqlCommand("INSERT INTO tblCategoryDetail(FieldLang,FieldHelp)Values(' " & dpLanguage.SelectedItem.Text & " ', " & convertC(c) & ")", con)

lblMsg.Text = "Values have stored in database"

con.Open()

Cmd.ExecuteNonQuery()

CatchexAs Exception

lblMsg.Text = ex.Message

EndTry

con.Close()

Public

Function UniToVar(ByVal sTextAsString)AsObject

Try

Dim b()AsByte

b = Encoding.Unicode.GetBytes(sText)

Return b

Catch exAs Exception

lblMsg.Text = ex.Message

EndTry

EndFunction

|||

i have posted the whole function in previous message......and need the solution in very short time...... hoping early resopnse by ur side

regards

Mubashar Ghazi

|||

I want to query the database using SQL statements that contain Arabic letters... for example, this query won't return any results that start with the letter '?' even though if I try any english letters it works perfectly:

SELECT ArtistID, Name
FROM dbo.Artist
WHERE (Name LIKE '?' + '%')

I also tried switching:

SELECT ArtistID, Name
FROM dbo.Artist
WHERE (Name LIKE '%' + '?')

but it won't work.. any ideas ?

Thanks :)

|||

See if the posthttp://forums.asp.net/t/1167422.aspx can be helpful.

No comments:

Post a Comment