UnitOfWork Generic Repository

The repository and unit of work patterns are intended to create an abstraction layer between the data access layer and the business logic layer of an application. Implementing these patterns can help insulate your application from changes in the data store and can facilitate automated unit testing or test-driven development (TDD). UnitOfwork public class UnitOfWork …

Export DataTable to Excel/CSV C#

protected void btnExport_Click(object sender, EventArgs e) { DataTable dtTable = new DataTable(); DataRow dtRow; dtTable.Columns.Add(“SNo”, typeof(int)); dtTable.Columns.Add(“Address”, typeof(string)); for (int i = 0; i <= 9; i++) { dtRow = dtTable.NewRow(); dtRow[0] = i; dtRow[1] = "Address " + i.ToString(); dtTable.Rows.Add(dtRow); } Response.ContentType = "Application/x-msexcel"; Response.AddHeader("content-disposition", "attachment;filename=test.csv"); Response.Write(ExportToCSVFile(dtTable)); Response.End(); } private string ExportToCSVFile(DataTable dtTable) { …