如何从varchar列中读取阿拉伯语文本?

时间:2017-06-20 08:48:36

标签: c# sqlite

我有sqlite数据库,他在varchar字段中存储阿拉伯文字 我使用了这段代码,但是当试图读取值时,问号就出现了字符

SQLiteConnection con = new SQLiteConnection("Data Source=Quran.sqlite;Version=3;");
SQLiteCommand cmd = new SQLiteCommand("SELECT Qtxt FROM tblQTxt'", con);
con.Open();
SQLiteDataReader dr = cmd.ExecuteReader();

dr.Read();
textBox1.Text = dr["Qtxt"].ToString();

dr.Close();
con.Close();

我使用" DB浏览器用于SQLite"从开放数据库中 当我尝试将字段视为二进制模式然后导出为文本时,我将看到真正的字符

DB Browser for SQLite

怎么能真正读到这个文件?

1 个答案:

答案 0 :(得分:0)

    SQLiteConnection con = new SQLiteConnection("Data Source=Quran.sqlite;Version=3;");
    SQLiteCommand cmd = new SQLiteCommand("SELECT Qtxt2 FROM tblQTxt where Sore='1' and Aye='1'", con);

    SQLiteDataAdapter dAdapter = new SQLiteDataAdapter(cmd);
    DataSet dSet = new DataSet();
    dAdapter.Fill(dSet);

    if (dSet.Tables[0].Rows.Count == 1)
    {

        Byte[] data = new Byte[0];
        data = (Byte[])(dSet.Tables[0].Rows[0]["Qtxt2"]);

        MemoryStream ms = new MemoryStream();
        ms.Write(data, 0, data.Length);

        ms.Position = 0;
        StreamReader reader = new StreamReader(ms,Encoding.GetEncoding(1256));
        string text = reader.ReadToEnd();
        textBox1.Text = text;

    }