C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






How to read data from an Excel spreadsheet into dataset


Posted Date: 31 May 2008    Resource Type: Code Snippets    Category: VB.NET Syntax

Posted By: Rekha       Member Level: Gold
Rating:     Points: 10



The following code sample shows to read data from an Excel spreadsheet into dataset

Dim cn As System.Data.OleDb.OleDbConnection
Dim cmd As System.Data.OleDb.OleDbDataAdapter
Dim ds As New System.Data.DataSet()

cn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" & _
"data source=C:\myData.XLS;Extended Properties=Excel 8.0;")

' Select the data from Sheet1 of the workbook.
cmd = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", cn)

cn.Open()
cmd.Fill(ds)
cn.Close()




Responses

Author: Roshan R Mhatre    02 Jun 2008Member Level: Gold   Points : 2
string Exceldb = Server.MapPath("UpLoaded_Files/") + inpfilename;
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Exceldb + ";" + "Extended Properties=Excel 8.0;";
//You must use the $ after the object you reference in the spreadsheet
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);

DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet, "ExcelInfo");
GridView1.DataSource = myDataSet.Tables["ExcelInfo"].DefaultView;
GridView1.DataBind();


try this this will help U a lot


Author: Roshan R Mhatre    02 Jun 2008Member Level: Gold   Points : 0



Importing Excel into SQL using ASP_NET
Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Getting a random number
Previous Resource: How to change upper case of 'cmbobox' in vb.net
Return to Discussion Resource Index
Post New Resource
Category: VB.NET Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing

Contact Us    Privacy Policy    Terms Of Use