Read Excel File into DataSet in ASP.

NET Using C# - CodeProject

http://www.codeproject.com/Tips/509179/Read-Excel-File-into-DataSe...

Not quite what you are looking for? You may want to try: Fast Excel file reader with basic functionality AnyDataFileToXmlConverter Class/Utility
9,890,640 members (52,431 online)

×
highlights off

home features

articles

quick answers help

discussions
read excel spreadsheet in c# and display into datatable

community

Articles » Web Development » ASP.NET » Samples

Next

Tip Browse Code Stats Revisions Alternatives Comments & Discussions (8)

Read Excel File into DataSet in ASP.NET Using C#
By Mannava Siva Aditya, 14 Dec 2012
4.20 (5 votes)

About Article
How to read Excel file data into a DataSet in ASP.NET using C#. Type Licence Tip/Trick CPOL 14 Dec 2012 17,351 14 times

Introduction
In this example I will explain how to read Excel file data into a DataSet in ASP.NET using C#. I have created an Excel file which contains the Slno, FirstName, LastName and Location which is shown below.

First Posted Views

Add your own alternative version

Bookmarked

C# ASP.NET Dev Intermediate

We would be putting all the data into the grid view and with the help of filter with the dropdown list box, we would filter the Slno and display accordingly, else display all the cell values in the grid. ASP:
Collapse | Copy Code

1 of 7

25/05/2013 01:11

GetFullPath(@"C:\InformationNew. oledbConn.HDR=YES. .Select -</asp:ListItem> </asp:DropDownList> <asp:GridView ID="grvData" runat="server"> </asp:GridView> C# code: Collapse | Copy Code OleDbConnection oledbConn.IO.Some of What's Coming Get the Insider News free each morning.ACE.Open().CommandType = CommandType. */ oledbConn = new OleDbConnection(@"Provider=Microsoft. // selecting distict list of Slno cmd.indicates the opposite.Tables["dsSlno"]." tells the driver to always read "intermixed" (numbers.SelectedValue). } } protected void ddlSlno_SelectedIndexChanged(object sender.12. protected void Page_Load(object sender.'. DataSet ds = new DataSet().NET and C# in 60 days Lab 11(Day 4) :Displaying Customer Screen 2 of 7 25/05/2013 01:11 . HDR=Yes .Data Source=" + path + ".0. Top News The Next Version of Android . OleDbDataAdapter oleda = new OleDbDataAdapter(). <asp:DropDownList ID="ddlSlno" runat="server" OnSelectedIndexChanged="ddlSlno_SelectedIndexChanged" AutoPostBack="true" AppendDataBoundItems="True"> <asp:ListItem Selected="True" Value="Select">. oleda = new OleDbDataAdapter(cmd).Fill(ds.indicates that the first row contains columnnames. /* connection string to work with excel file.Text. not data."). oleda. "dsSlno"). ddlSlno.DataSource = ds. Note that this option might affect excel sheet write access negative. strings etc) data columns as text.DefaultView. cmd.0. Related Videos Learn .Extended Properties='Excel 12. cmd.CodeProject http://www.DataTextField = "Slno".DataBind(). EventArgs e) { if (!IsPostBack) { GenerateExcelData("Select").xls").Path.DataValueField = "Slno". dates..codeproject. } private void GenerateExcelData(string SlnoAbbreviation) { // need to pass relative path after deploying on server string path = System.com/Tips/509179/Read-Excel-File-into-DataSe. IMEX=1.NET Using C# . EventArgs e) { GenerateExcelData(ddlSlno. ddlSlno. "IMEX=1. OleDbCommand cmd = new OleDbCommand().Connection = oledbConn.CommandText = "SELECT distinct([Slno]) FROM [Sheet1$]".. HDR=No .OLEDB. // passing list of states to drop-down list ddlSlno. ddlSlno.Read Excel File into DataSet in ASP.

A Class to Read and Write to Excel and Text Delimited Spreadsheet Fast Excel file reader with basic functionality BasicExcel . along with any associated source code and files. is licensed under The Code Project Open License (CPOL) About the Author Mannava Siva Aditya Web Developer India Member Follow on Twitter Google AnyDataFileToXmlConverter Class/Utility NASA Space Shuttle TV Schedule Transfer to Outlook Calendar DataTable to Excel How to Read and Write ODF/ODS Files (OpenDocument Spreadsheets) Placing images in Excel using automation Excel to SQL without JET or OLE Displaying Charts in SharePoint using Excel Services Read Excel in ASP. India.CommandText = "SELECT [Slno]. cmd.codeproject.NET License This article. } oleda = new OleDbDataAdapter(cmd).DefaultView. I am Microsoft Certified Technology Specialist. // binding form data with grid view grvData. I ResxWriter: Generating .CommandText = "SELECT [Slno].Close(). beginning with Microsoft's technologies ASP. oleda. } else { cmd.NET. Where as in IT Development industry since 27. } // need to catch possible exceptions catch (Exception ex) {} finally { oledbConn.IsNullOrEmpty(SlnoAbbreviation) && SlnoAbbreviation != "Select") { cmd.NET I am a 28 year old software web developer from Hyderabad.Tables[0]. // by default we will show form data for all states but if any state is selected then show data accordingly if (!String.AddWithValue("Slno_Abbreviation". Approximately 3 years ago.A Class to Read and Write to Microsoft Excel Converting a List of Data to XML using Microsoft Excel 2003 How to create Microsoft Excel 2007 files on the server Microsoft Office XML formats. grvData.NET Using C# .Parameters.DataSource = ds. SlnoAbbreviation). [LastName].com/Tips/509179/Read-Excel-File-into-DataSe.resx files from an Excel spreadsheet 3 of 7 25/05/2013 01:11 . I have been working since approximately age 25.[FirstName]. } }// close of method GemerateExceLData Displaying JSON Data Related Articles CSpreadSheet . defective by design? Yet another way to Generate Excel documents programmatically Creating basic Excel workbook with Open XML Excel to SQL without JET or OLE (Version 2) Using ASP.[Location]" + " FROM [Sheet1$] where [Slno]= @Slno_Abbreviation".[Location] FROM [Sheet1$]".NET MVC and the OpenXML API to Stream Excel Files A Quick Guideline for Microsoft Windows PowerShell: Part 3 RefEdit Emulation for .Fill(ds).Read Excel File into DataSet in ASP.DataBind()..[FirstName]. [LastName].. I have taught myself in development.CodeProject http://www.

Net to create distributed. Now I am working as a web developer where my roles make me purely in web based technology solutions which manage and control access to applications and patient information stored in legacy systems.0) and have been learning every new technology being introduced.CodeProject http://www. I have worked on various . was given an opportunity to work as a freelance in the tech field. Which became my passion. I too had an opportunity to train some IT professionals with technical skills in development area. Article Top Like 3 1 Tweet 7 Rate this: Poor Excellent Vote Comments and Discussions Add a Comment or Question Search this forum Profile popups Spacing Relaxed Open All Go Noise Medium Per page 25 Layout Update First Prev Next Thanks Good Job Alireza_1362 12 May '13 . 3.5.NET framework versions(2. Currently.10:39 Why not make use of the Interop Assemblies for Office? 4 of 7 25/05/2013 01:11 ... 4. I am looking forward to working in R & D in .NET Using C# . reusable applications.0 .com/Tips/509179/Read-Excel-File-into-DataSe. client-server applications.6:54 Reply · View Thread · Permalink · Bookmark My vote of 1 JamesPChadwick 21 Dec '12 .codeproject.Read Excel File into DataSet in ASP.

Read Excel File into DataSet in ASP.codeproject. In search of some reference 5 of 7 25/05/2013 01:11 .aspx?id=23734[^] Did you run into any field limitations? My impression is that there is a 255 character limit AND the maximum length of the first 8 rows in a column sets the maximum for the document.. Reply · Email · View Thread · Permalink · Bookmark Re: Where do you get the provider? Mannava Siva Aditya 17 Dec '12 .Extended Properties='Excel 12.com/Tips/509179/Read-Excel-File-into-DataSe.OLEDB. IMEX=1.").HDR=YES. Perhaps you missunderstood my question about the ACE provider but any provider needs to have a driver installed on the computer. So if row 9 has 255 characters only the initial max length is available. This it self is the provider for microsoft excel.12:05 In general this is a good start but it is incomplete and the responses to my questions are incorrect.microsoft.ACE.net.'.0.12.CodeProject http://www.com/en-us/download /details..Data Source=" + path + ".10:28 Do you have Excel installed on your web server or are you installing something like Access Database Engine? http://www...19:58 new OleDbConnection(@"Provider=Microsoft. I'm not sure how you think this all works but the provider is not part of .0. And comming to field limitation it will read what ever data is been entered! Reply · Email · View Thread · Permalink · Bookmark Re: Where do you get the provider? xx_Sandman_xx 18 Dec '12 . Reply · View Thread · Permalink · Bookmark Where do you get the provider? xx_Sandman_xx 17 Dec '12 .NET Using C# .

wordpress. too...19:27 It would support both xls and xlsx.Read Excel File into DataSet in ASP.. material outside of my statements I discovered a very complete article here.0 16 Dec '12 .com/Tips/509179/Read-Excel-File-into-DataSe. Reply · Email · View Thread · Permalink · Bookmark Re: My vote of 5 Carsten V2.22:40 Very useful tipp! Thanks for sharing.130523. Reply · View Thread · Permalink · Bookmark Re: My vote of 5 Mannava Siva Aditya 16 Dec '12 . 1999-2013 Terms of Use 6 of 7 25/05/2013 01:11 ..com/2011/02 /05/how-to-read-or-write-excel-file-usingace-oledb-data-provider/[^] In the future I would suggest if you don't understand the question or know the answer not to post guess as fact. I think it would be helpful to post the string for older versions.6.22:05 Ok..CodeProject http://www..1 | Last Updated 14 Dec 2012 Question Bug Layout: fixed | fluid Article Copyright 2012 by Mannava Siva Aditya Everything else Copyright © CodeProject. Reply · Email · View Thread · Permalink · Bookmark My vote of 5 Carsten V2.0 14 Dec '12 .NET Using C# . Nevertheless a very useful tipp! Reply · View Thread · Permalink · Bookmark Last Visit: 23 May '13 . as we had taken the latest one. http://yoursandmyideas. If I am right your connection-string supports only XLSX-documents.codeproject.6:50 19:36 Last Update: 23 May '13 - Refresh 1 General News Suggestion Answer Joke Rant Admin Permalink | Advertise | Privacy | Mobile Web01 | 2. sorry! It was my bad.

.CodeProject http://www.codeproject..NET Using C# .com/Tips/509179/Read-Excel-File-into-DataSe. 7 of 7 25/05/2013 01:11 .Read Excel File into DataSet in ASP.