首页 > 解决方案 > 如何将数据表中的数据加载到 resx 文件中?

问题描述

我已将数据库中的数据提取到数据表中。现在我想将此数据表中的数据添加到 resx 文件中。我已经创建了一个这样的 resx 文件和数据表。

class LoadData
{
public static void main(string[] args)
{
string FilePath=@"C:\"
DataTable dt = new DataTable();
using(ResXResourceWriter rxrw = new ResXResourceWriter(FilePath+"Demo.resx"))
{
SqlConnection conn=new SqlConnection();
conn.ConnectionString="my connection string here";
SqlCommand cmd= new SqlCommand("my sql command here",conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
conn.Close;
da.Dispose();
}
}
}

那么如何将数据表 dt 中的数据加载到 Demo.resx 文件中?

标签: c#.net

解决方案


你可以做类似的事情

public class Example
{
   public static void Main()
   {
      // Instantiate an Automobile object.
      Automobile car1 = new Automobile("Ford", "Model N", 1906, 0, 4);
      Automobile car2 = new Automobile("Ford", "Model T", 1909, 2, 4);
      // Define a resource file named CarResources.resx.
      using (ResXResourceWriter resx = new ResXResourceWriter(@".\CarResources.resx"))
      {
         resx.AddResource("Title", "Classic American Cars");
         resx.AddResource("HeaderString1", "Make");
         resx.AddResource("HeaderString2", "Model");
         resx.AddResource("HeaderString3", "Year");
         resx.AddResource("HeaderString4", "Doors");
         resx.AddResource("HeaderString5", "Cylinders");
         resx.AddResource("Information", SystemIcons.Information);
         resx.AddResource("EarlyAuto1", car1);
         resx.AddResource("EarlyAuto2", car2);
      }
   }

参考https://docs.microsoft.com/en-us/dotnet/framework/resources/working-with-resx-files-programmatically


推荐阅读