Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 4th, 2005, 10:07 PM
Authorized User
 
Join Date: Aug 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to macupryk Send a message via Yahoo to macupryk
Default CONVERTING EXCEL TO DATASET C#

I NEED TO CONVERT SELECT * FROM SampleSheet$A1:D20
                                       TO INFINITE
IS IT POSSIBLE?

THE FOLLOWING CODE HAS TO BE EXECUTED. IS THERE A WAY AROUND?
PLEASE GET BACK TO ME ASAP. THANKS.



private void Page_Load(object sender, System.EventArgs e)
          {
               // Put user code to initialize the page here
               // Create connection string variable. Modify the "Data Source"
               // parameter as appropriate for your environment.
               String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                    "Data Source=" + Server.MapPath("../ExcelData.xls") + ";" +
                    "Extended Properties=Excel 8.0;";

               // Create connection object by using the preceding connection string.
               OleDbConnection objConn = new OleDbConnection(sConnectionString);

               // Open connection with the database.
               objConn.Open();

               // The code to follow uses a SQL SELECT command to display the data from the worksheet.

               // Create new OleDbCommand to return data from worksheet.
               OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM ExcelData$", objConn);


               // Create new OleDbDataAdapter that is used to build a DataSet
               // based on the preceding SQL SELECT statement.
               OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

               // Pass the Select command to the adapter.
               objAdapter1.SelectCommand = objCmdSelect;

               // Create new DataSet to hold information from the worksheet.
               DataSet objDataset1 = new DataSet();

               // Fill the DataSet with the information from the worksheet.
               objAdapter1.Fill(objDataset1, "XLData");

               // Bind data to DataGrid control.
               DataGrid1.DataSource = objDataset1.Tables[0].DefaultView;
               DataGrid1.DataBind();

               // Clean up objects.
               objConn.Close();
          }

Knowledge is to be shared.
__________________
Knowledge is to be shared.
 
Old March 9th, 2010, 11:22 AM
Registered User
 
Join Date: Mar 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

you can import Excel to DataSet easily with GemBox.Spreadsheet C# Excel component.

Here is a code snippet:

Code:
private void Page_Load(object sender, System.EventArgs e)
{
	var ef = new ExcelFile();
	ef.LoadXls(Server.MapPath("../ExcelData.xls"));

	// Initialize DataTable (skip this if you have DataTable definition)
	var dt = new DataTable();
	dt.Columns.Add("name", typeof(string));
	dt.Columns.Add("birth", typeof(DateTime));

	// Extract data to DataTable
	ws.ExtractToDataTable(dt, ws.Rows.Count, ExtractDataOptions.StopAtFirstEmptyRow, ws.Rows[0], ws.Columns[0]);

	DataGrid1.DataSource = dt.DefaultView;
	DataGrid1.DataBind();
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Excel to Mysql Tutorial klyau23 MySQL 3 May 12th, 2007 07:56 AM
Converting a untyped dataset to a typed dataset daphnean Visual Studio 2005 0 July 13th, 2006 01:16 AM
Converting excel data to Access using excel VBA ShaileshShinde VB Databases Basics 1 April 26th, 2006 07:57 AM
Converting report to Excel anukagni Access 2 February 18th, 2006 03:34 AM
converting formula in excel ct Excel VBA 0 October 5th, 2005 10:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.