-1

I have a strange string looks like this on the database

"இரண்டு வருடங்கள்"

On browser it displays correctly like this

"இரண்டு வருடங்கள்" (this is the correct way)

The problem is I cant search for phrases properly on database as its stored in a weird way. How do I convert to proper unicode like this "இரண்டு வருடங்கள்" and store?

//The database field is properly set to NVarchar and if I directly store the correct value it stays like that on database, so the problem is not there.

I need to find a way to convert the source string properly from that weird unicode format to proper Unicode and store on database.

note: I have tried these guides and didnt work.

Convert Unicode string into proper string

C# Convert string from UTF-8 to ISO-8859-1 (Latin1) H

My insert code looks like this:

string insertSql = @"INSERT INTO Importer (Heading, Url) VALUES (@0, @1)";
using (SqlCommand insertCmd = new SqlCommand(insertSql, con))
{
    insertCmd.Parameters.AddWithValue("@0", heading);
    insertCmd.Parameters.AddWithValue("@1", url);
    insertCmd.ExecuteNonQuery();
}

Field is declared as:

[Heading] [nvarchar](500) NULL

Database is not a problem, I have tried insert the correct string and its being stored. The only problem is that weird formated Unicode string which is being stored like that, but when viewed on the browser it displays correctly.

You can try copy the string on a html file and view it on browser. It will show correctly, but when you view the source it will be in the wrong weird way.

Try creating a html file with this content and view on your browser and look at the source code as well.

"இரண்டு வருடங்கள்"
Danny Web
  • 217
  • 5
  • 17

2 Answers2

0

You don't show your SQL, but this example should work. Note the 'N' is very important.

INSERT INTO YourTable(YourColumn) values (N'இரண்டு வருடங்கள்')
Kevin
  • 2,566
  • 1
  • 11
  • 12
  • inserting like u said is not a problem. the problem the source im getting the string from comes in that weird unicode format and it stores like that on databae. – Danny Web Feb 04 '20 at 03:36
0

I found the solution, I just need to decode it before inserting and everything looks fine.

HttpUtility.HtmlDecode(heading)

that weird string is Unicode HtmlEncoded string.

Danny Web
  • 217
  • 5
  • 17