C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » VB.NET Syntax »

How to read data from an Excel spreadsheet into dataset


Posted Date: 31 May 2008    Resource Type: Code Snippets    Category: VB.NET Syntax
Author: RekhaMember Level: Gold    
Rating: 1 out of 5Points: 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  
Sign In to add 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!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use