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 !




Excel to Dataset


Posted Date: 25 Jan 2008    Resource Type: Code Snippets    Category: ADO.NET

Posted By: Amit Dave       Member Level: Bronze
Rating:     Points: 10



This code is used to fill up the databaset from excel file. And hope it will help our community.


namespace ExcelPOCApps
{
public class ExcelReader
{

string OledbConnectionString = string.Empty;
private OleDbConnection objConn = null;


public ExcelReader ( string ExcelFilePath )
{
OledbConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ExcelFilePath + ";Extended Properties=Excel 8.0;";
objConn = new OleDbConnection(OledbConnectionString);
}

public DataTable GetExcelData ()
{
try
{

if(objConn.State == ConnectionState.Closed)
{
objConn.Open();
}
else
objConn.Open();

OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Data$]", objConn);

OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

objAdapter1.SelectCommand = objCmdSelect;

DataSet objDataset1 = new DataSet();

objAdapter1.Fill(objDataset1);

objConn.Close();

return objDataset1.Tables[0];

}
catch(Exception ex)
{
objConn.Close();
throw ex;
}
}
}



}








Responses


No responses found. Be the first to respond and make money from revenue sharing program.

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: Disabling/Enabling Controls w/Checkbox
Previous Resource: Mysql Connection Strings
Return to Discussion Resource Index
Post New Resource
Category: ADO.NET


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

it help desk

Contact Us    Privacy Policy    Terms Of Use