.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Loading from an Excel File to the dataset

Posted By:Suderson Sarathy       Posted Date: November 22, 2010    Points: 15    Category: File Operation    URL: http://www.dotnetspark.com  

This article shows on how to load from an Excel File to the C# windows Application dataset

This describes on how to store the excel datas into the C# Dataset. Please replace "uploadpathforfpl1 " with your Excel File Path

Filename1 - your table name
connforexcel1 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + uploadpathforfpl1 + ";Extended Properties=Excel 8.0;";

//Creates a table in the name of the file what user selects
dtExcel = new System.Data.DataTable(Filename1);

// This checks whether the user selected file is already uploaded in the dataset
if ((dstExcelCreate.Tables.Contains(Filename1) == true))

   // If it is already available it will be removed from the dataset.


 // Add the user selected file in the form of table to the dataset

conn = new OleDbConnection(connforexcel1);
if (conn.State == ConnectionState.Closed)


cmd = new OleDbCommand("SELECT * FROM [Sheet$] where [Email Address ] is not null", conn);
da = new OleDbDataAdapter();
da.SelectCommand = cmd;
da.Fill(dstExcelCreate, Filename1);



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend