How to Add Excel Data in DataTable

Sometimes, we need to export our excel data in database or datatable. In this blog, we will create method to read excel data and add data into datatable. 
 
You can enter some data with header column as shown in following screen shot. There are three column(Employee Name, Salary and Country).  
 
 
 
Develop Function/Method  for get excel data into DataTable
 
Now, we need to get data from excel with proper header. We will pass excel range in our method to get data. In our sample, your excel range would be B6:D10. You need to pass your excel range as argument in this method.
 
First loop is add columns in datatable. Second loop is skip header row and add actual data in data table. You can see code snippet same as shown in following screen shot. 
 
 
OutPut Of data in datatable
 
Once , you will use above method in your code, you can see output as shown in following screen shot.
 
  
Ebook Download
View all
Learn
View all