开发者

export data set to csv file using C#

开发者 https://www.devze.com 2023-03-05 22:17 出处:网络
how to export Data from sql s开发者_如何学Cerver into csv file using c# Eg; Select name,id from employee

how to export Data from sql s开发者_如何学Cerver into csv file using c#

Eg;

Select name,id from employee

Name id

XXX 1 ZZZ 2 AAA 3

This result will be stored in the CSV File.


Using Filehelpers and Dapper.

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

In some method somewhere:

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

精彩评论

暂无评论...
验证码 换一张
取 消