c# - 如何将数据表中的数据加载到 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 文件中?
解决方案
你可以做类似的事情
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
推荐阅读
- ansible - Ansible 断言模块失败并显示“检测到无效条件:无效语法 (
, 第 1 行)" - node.js - 错误 [ERR_HTTP_HEADERS_SENT]:在使用 Firebase 将标头发送到客户端 NodeJS 后无法设置标头
- javascript - Chrome 扩展程序拒绝将字符串评估为 JavaScript,因为 emscripten 生成的文件中存在“unsafe-eval”
- flutter - 使用 ImagePicker 上传图片
- r - R Shiny - 如何在一个会话中同时执行多项任务?如两次计算或两次定时器
- oracle - 数据库作业调度器时间限制
- python - AMQP 1.0 消息发送困难
- python - 如何在 docker 中运行 python 脚本并在本地保存结果?
- javascript - React 组件未显示正确的渲染计数
- python - Python Tkinter:循环运行时窗口冻结