从sqlite数据库读取阿拉伯语文本返回垃圾

时间:2013-11-12 11:55:52

标签: wpf sqlite

我有这个代码从sql lite数据库读取数据并在wpf应用程序中以手风琴显示

       int la = 1;
       if (langid == "Arabic")
       {
           la = 2;

       }
       DbCommand cmdSelect = conn.CreateCommand();
       // cmdSelect.CommandText = "SELECT id from GenericContentCategories where UniqueName=@UniqueName and  languageId=@langid";


       List<GenericContentView> res = new List<GenericContentView>();

           cmdSelect.CommandText = "SELECT title,content,MainImage,startDate from News where  languageId=@langid";
           DatabaseManager.AddParameter(cmdSelect, "@UniqueName", UniqeName);
           DatabaseManager.AddParameter(cmdSelect, "@langid", la);
           var reader = cmdSelect.ExecuteReader();

           while (reader.Read())
           {
               GenericContentView fetchedItem = new GenericContentView();
               fetchedItem.Title = reader["title"] as string;
               fetchedItem.Content = reader["content"] as string;
               fetchedItem.MainImage = reader["MainImage"] as string;
               fetchedItem.startDate = (reader["startDate"] as DateTime?).Value;
               res.Add(fetchedItem);

       }
       return res;

}

项目内容在垃圾数据中返回阿拉伯语

这是代码将此数据从sql server写入sqllite

public void CacheEntries(DateTime lastCacheTime)        {            列出cats = new List();

       cats.AddRange(GetGenericCategories(new DateTime(), null, 1));
       cats.AddRange(GetGenericCategories(new DateTime(), null, 2));


       List<GenericContentView> Contents = new List<GenericContentView>();
       Contents.AddRange(GetGenericItems(new DateTime(), null, 1));
       Contents.AddRange(GetGenericItems(new DateTime(), null, 2));


       DatabaseManager.Instance.OpenConnection();

       DbConnection conn = DatabaseManager.Instance.GetConnection();
       DbTransaction transaction = conn.BeginTransaction();

       try
       {
           DbCommand cmdGCCreate = conn.CreateCommand();
           cmdGCCreate.CommandText = "CREATE TABLE IF NOT EXISTS GenericContent (id INTEGER PRIMARY KEY, title VARCHAR(255),UniqueName VARCHAR(255),content VARCAHR(5000), startDate DATETIME, relatedEntities VARCHAR(5000), MainImage VARCHAR(5000),Description VARCHAR(5000), categoryId VARCHAR(5000))";
           cmdGCCreate.ExecuteNonQuery();

           DbCommand cmdInsertGC = conn.CreateCommand();
           DbCommand cmdUpdateGC = conn.CreateCommand();
           cmdInsertGC.CommandText = "INSERT OR IGNORE INTO GenericContent (id) VALUES (@id)";
           cmdUpdateGC.CommandText = "Update GenericContent SET title = @title,UniqueName=@UniqueName, content = @content, startDate = @startDate, relatedEntities = @relatedEntities,Description=@Description, categoryId = @categoryId,MainImage=@MainImage WHERE id = @id";

           DbCommand cmdCatCreate = conn.CreateCommand();
           cmdCatCreate.CommandText = "CREATE TABLE IF NOT EXISTS GenericContentCategories (id INTEGER PRIMARY KEY, parentId Integer, name VARCAHR(5000), languageId Integer,UniqueName VARCHAR(255))";
           cmdCatCreate.ExecuteNonQuery();

           DbCommand cmdInsertCat = conn.CreateCommand();
           DbCommand cmdUpdateCat = conn.CreateCommand();
           cmdInsertCat.CommandText = "INSERT OR IGNORE INTO GenericContentCategories (id) VALUES (@id)";
           cmdUpdateCat.CommandText = "Update GenericContentCategories SET parentId = @parentId, name = @name, languageId = @languageId,UniqueName=@UniqueName WHERE id = @id";

           AddCategories(cats.ToArray(), null,cmdInsertCat, cmdUpdateCat);

           AddGenericContent(Contents,cmdInsertGC, cmdUpdateGC);

           transaction.Commit();
       }
       catch (Exception e)
       {
           LOG.ERROR(e);
           transaction.Rollback();
       }
       finally
       {
           DatabaseManager.Instance.CloseConnection();
       }

   }

1 个答案:

答案 0 :(得分:0)

问题在于数据是未格式化的HTML