Introduction

This article is about binding a database table to a GridView and exporting the GridView data to an Excel text file.
An Excel file is used to store information. Data export to Excel is an easy way to maintain record sheets like reports. Similarly,
the generated text file is used to extract data and used to process data or pass
to an application as input data.

The application

Create a Windows application in C# .NET 2010 and designed as shown below:

Import Namespaces as follows:

using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.VisualBasic;