使用C#将数据集导出到CSV文件 [英] export data set to csv file using C#

查看:526
本文介绍了使用C#将数据集导出到CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c#将数据从sql server导出到csv文件中

how to export Data from sql server into csv file using c#

例如;

选择名称,员工的ID

Select name,id from employee

姓名ID

XXX 1
ZZZ 2
AAA 3

XXX 1 ZZZ 2 AAA 3

此结果将存储在CSV文件中。

This result will be stored in the CSV File.

推荐答案

使用 Filehelpers Dapper

[DelimitedRecord(",")] 
public class Employee 
{ 
    public string Name;
    public int Id; 
}

以某种方式在某处:

var employees = connection.Query<Employee>("select Name, Id from employee");
FileHelperEngine engine = new FileHelperEngine(typeof(Employee));
engine.WriteFile("employees.csv", employees);

这篇关于使用C#将数据集导出到CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆