Thursday, September 30, 2010
Todays post is about how to load data from excel sheet. This post is emphasized on following file formats:
1) xls (Excel Sheet 1997-2003)
2) xlsx (Excel Sheet 2007)
Both sheets require connection string to extract data from sheet.
Connection String for xls:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Sample1.xls;Extended Properties=Excel 8.0"
Connection String for xlsx:
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Sample.xlsx;Extended Properties=Excel 12.0"
Below is a small program for your understanding. The program is in ASP.NET.
protected void Page_Load(object sender, EventArgs e)
string connString = ConfigurationManager.ConnectionStrings["xls"].ConnectionString;
// Create the connection object
OleDbConnection oledbConn = new OleDbConnection(connString);
// Open connection
// Create OleDbCommand object and select data from worksheet Sheet1
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
// Create new OleDbDataAdapter
OleDbDataAdapter oleda = new OleDbDataAdapter();
oleda.SelectCommand = cmd;
// Create a DataSet which will hold the data extracted from the worksheet.
DataSet ds = new DataSet();
// Fill the DataSet from the data extracted from the worksheet.
// Bind the data to the GridView
GridView1.DataSource = ds.Tables.DefaultView;
I hope this will help you.
Dear Folks, Log4j is a logging framework, i.e. it provides the code to log messages while Commons-logging is an abstraction layer for log...
In my case, this error pertains to Oracle Merge query . After 30 minutes of time wastage and a lot of hunting on different forums, I come to...
The sign-in method you're trying to use isn't allowed. For more info, contact your network administratorAbove problem occur when you have not added a group (of which User try to login) in your local policy login. To resolve the issue, follow t...
Yesterday, I start SQL Server 2005 and try to connect with sa user but was enable to connect with the 'sa' user and got this error: ...