2016-12-25 41 views

回答

1

如果我得到它的權利,你要在不同的表中的每個值填充你的資源文件DataBase動態。你可以做到這一點通過在項目中創建.resx文件,下一步將使用其內容下面的代碼是添加/更新

public static void AddOrUpdateResource(string key, string value) 
     { 
      var path = @"YourResourceFilePath.resx"; 
      var resx = new List<DictionaryEntry>(); 
      using (var reader = new ResXResourceReader(path)) 
      { 
       resx = reader.Cast<DictionaryEntry>().ToList(); 
       var existingResource = resx.Where(r => r.Key.ToString() == key).FirstOrDefault(); 
       if (existingResource.Key == null && existingResource.Value == null) // NEW! 
       { 
        resx.Add(new DictionaryEntry() { Key = key, Value = value }); 
       } 
       else // MODIFIED RESOURCE! 
       { 
        var modifiedResx = new DictionaryEntry() { Key = existingResource.Key, Value = value }; 
        resx.Remove(existingResource); // REMOVING RESOURCE! 
        resx.Add(modifiedResx); // AND THEN ADDING RESOURCE! 
       } 
      } 
      using (var writer = new ResXResourceWriter(path)) 
      { 
       resx.ForEach(r => 
       { 
        // Again Adding all resource to generate with final items 
        writer.AddResource(r.Key.ToString(), r.Value.ToString()); 
       }); 
       writer.Generate(); 
      } 
     } 

然後你就可以調用此方法,並從傳遞鍵值你的DataBase

+0

我是從數據庫中完成的,它需要一些時間,但它的大量數據 – khaled