1

I work with Sqlite database in C# and I have this question: Does Sqlite database support Persian/Arabic encoding? Because I have written some Arabic/Persian data in it and when I want to read data from database it is read in unsuitable form!!!enter image description here

my code :

int len = ds.Tables["tbl"].Rows.Count;
            int index = rnd.Next(0, len - 1);
            //notifyIcon1.ShowBalloonTip(15, "پیام عشق ", ds.Tables["tbl"].Rows[index][0].ToString(), ToolTipIcon.Info);
            string str = ds.Tables["tbl"].Rows[index][0].ToString();
            MessageBox.Show(str);

thanks .

next of my code :

DataSet ds;
ds = SQLite_DB.Select_DB(SQLite_DB.Con_string("data.s3db"), "select * from info");
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
salar_cpp_cs
  • 43
  • 2
  • 6

2 Answers2

2

So long as you're using Version 3 or higher, you'll be able to use UTF-8 / UTF-16, which is your best bet for Arabic.

Will A
  • 24,780
  • 5
  • 50
  • 61
0

In short: No.

SQLite support only a very, very limited number of encodings: UTF-8 and UTF-16 (multiple varieties).

Fortunately, UTF-8 is perfectly suitable for expressing Arabic or Persian, or any other language (including Klingon, should the fancy grab you).

It is posible, of course, that some other part of your toolchain is bungling the encoding, check the documentation for the C#.net SQLite wrapper, and your Forms code.

Williham Totland
  • 28,471
  • 6
  • 52
  • 68
  • @salar_cpp_cs: Go through your entire toolchain, and test for UTF-8 cleanliness at every level. Check that the database is well-formed, using an external executable like sqlite3.exe (this might be named differently on your platform); check that your source files are UTF-8 encoded, check that any appropriate compiler flags are set, check that any ancillary files are properly encoded and read correctly, learn how to use the C# l10n and i18n utilities, and understand some of the core concepts of character encoding and how SQLite is designed. For starters. – Williham Totland May 16 '11 at 17:48
  • Williham is correct - you need to verify that garbage isn't going in. If you're using System.Data.Sqlite, put a breakpoint at where you're inserting the data. Presumably, you're doing this via a SqliteCommand parameter. Look at what the parameter's value is - if that's garbage, then you're bungling the encoding. System.Data.Sqlite will accept a CLR string (basically, UCS2) and convert it to UTF-8 for you, so as long as your string going in looks good, it should come out correctly a well. – Kevin Hsu May 16 '11 at 18:43