0

My query looks like:

string str = string.Format("Insert into [MyDB].[dbo].[tlb1] ([file_path],[CONTENT1],[CONTENT2]) values ('{0}','{1}','{2}');", fullpath, _val[0], _val[1]);

Now when I insert data into database if array _val[] contains data in english language it insert correctly but when array contains data in Russian Language in database this show like ??????????????????????? Is there a way to insert data in Russian Language from an array.

3
  • What's the type of the database fields you're inserting to? Commented May 15, 2012 at 10:52
  • Wich database you use? What codepage choised for this fields? Commented May 15, 2012 at 10:52
  • DataBase version: Microsoft SQL Server 2005 and fields are of nvarchar(max) Commented May 15, 2012 at 10:54

4 Answers 4

2

According to this (Archived) Microsoft Support Issue:

You must precede all Unicode strings with a prefix N when you deal with Unicode string constants in SQL Server

Sign up to request clarification or add additional context in comments.

Comments

1

First of all, you should use prepared statements and let the database driver insert the placeholders correctly (i.e. SqlCommand with parameters). Then the issue should go away (as well as any potential SQL injection problems).

As a quick fix in your case: Prefix the string literals you're inserting with N:

... values (N'{0}',N'{1}',N'{2}')

This causes the literals to be Unicode literals, not arbitrary-legacy-codepage ones and thus preventing the conversion from Unicode to the legacy codepage (which results in question marks for characters that cannot be represented).

Comments

0

It seems that the datatype of columns [Content1] and [Content2] is nchar. You should convert the columns to nvarchar which is used to store unicode data.

2 Comments

datatype of columns is nvarchar not nchar
Then try checking the collation of your server/database. More info here msdn.microsoft.com/en-us/library/ms143726(v=sql.90).aspx
0

First of all you must see Database codepage at server. May be non-Unicode CP in database, but data from your app comes in Unicode format.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.