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) { 猫のリスト = 新しい 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();
}
}