Friday 16 October 2015

Unable to display nvarchar in while using datarow

Dear friend day to day i try to share all my personal experience to you, so that you could save your time to get any solution. Today i am going to share an amazing experience.
I was using datatable and datarow in to diaplay some db table value on web page.
But there was a problem i was using nvarchar in sql table. So our db has both english and hindi content in column. But on page when i was try to display data from datarow, hindi content was in unreadable format. You can see data in table and how it was looking on webpage in given figure.

What i was assuming that conversion of sting into UTF 8 will work for me, but it didn't.
byte[] bytes = Encoding.Default.GetBytes(dt_all.Rows[0]["title"].ToString() );
string myString = Encoding.UTF8.GetString(bytes);

Then i tried 
string name = "गुरु";

Still :(


Finally i got solution by adding a single line code on page.