reading data from excel using OLEDB

  • Thread starter Thread starter Shees Abidi
  • Start date Start date
S

Shees Abidi

I read an article on the link:
http://support.microsoft.com/default.aspx?scid=kb;en-us;306572 related to
reading data from Excel using OLEDB The topic's heading is: How to query and
display excel data by using ASP.NET, ADO.NET, and Visual C# .NET
I am trying with the same code in Visual Studio 2005 in ASP.NET application.
The code i am using is:
protected void Page_Load(object sender, EventArgs e)
{

String connectionString =@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\wwwroot\ExcelData.xls;Extended Properties=Excel 8.0;";
OleDbConnection con = new OleDbConnection(connectionString);
con.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM myrange1", con);

OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "XLData");
//da.Fill(ds, "ExcelData");
GridView1.DataSource = ds.Tables[0].DefaultView;
//GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();

}
I have included name space:using System.Data.OleDb;
The problem is when i execute the application following exception is coming:
The Microsoft Jet database engine could not find the object 'myrange1'.
Make sure the object exists and that you spell its name and the path name
correctly.
I have followed the same steps while creating Excel file and have given the
same names but still having the problem Please help..
 
Try
[range1$]

When googling, search for
[Sheet1$]

which is the most common example type syntax
 
Back
Top