0

I have the following query in ASP.Net page:

SELECT 'محاولة'

This query is printing a hard coded Arabic word. I am saving this record in a DataTable and then printing on page in GridView (by passing that DataTable to GridView) but this Arabic word is being printed as square boxes.

How to print this word properly on ASP.Net page? I tried using following but it didn't work.

SELECT N'محاولة'

EDIT

Here's my code.

DataTable dt = new DataTable();

string sql = "SELECT 'محاولة'";

command.Connection = con;
command.CommandType = CommandType.Text;
command.CommandText = sql;
reader = command.ExecuteReader();
dt.Load(reader);

And then I am passing this "dt" to gridview control.

GridView1.DataSource = dt;
GridView1.DataBind();

Grid view is printing that Arabic word as square boxes (screenshot below).

enter image description here

Frank Martin
  • 3,147
  • 16
  • 52
  • 73
  • You probably want to use UTF-8 on your page... – Laurent S. Jun 22 '15 at 07:47
  • I already did but it didn't help. – Frank Martin Jun 22 '15 at 07:52
  • Character encoding issues can come from a lot of different places. It might aswell be your database failing, although you don't actually get anything from there. That said I see absolutely no point in what you're doing. Opening a connection to a database to fetch nothing from there is a waste of time and ressources. – Laurent S. Jun 22 '15 at 07:55
  • This query is just small part of large query which I have not printed here. Basically I am running two queries and saving them in two data tables. Then I merge those data tables. But I need to differentiate between those two types of records so I am selecting this hard coded value from each query (hard coded Arabic words are different for both queries) – Frank Martin Jun 22 '15 at 08:22
  • Ok I get it better now :-) I would suggest you to read out [this question](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) explaining the many point of concerns when dealing with UTF-8 – Laurent S. Jun 22 '15 at 08:27

1 Answers1

0

Let assume your table structure is as fallow.

Create table Arabic(
id int primary key identity,
Title narchar(100),
);

Now lets add some demo data.

Insert into Arabic values (N'محاوله');

After adding data correctly there you won't have any problem with loading it asp.net page.

user3127648
  • 1,367
  • 12
  • 26