By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,412 Members | 2,896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,412 IT Pros & Developers. It's quick & easy.

reading data from excel using OLEDB

P: n/a
I read an article on the link:
http://support.microsoft.com/default...b;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..

Oct 28 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Try
[range1$]

When googling, search for
[Sheet1$]

which is the most common example type syntax

"Shees Abidi" <Shees Ab***@discussions.microsoft.comwrote in message
news:BE**********************************@microsof t.com...
>I read an article on the link:
http://support.microsoft.com/default...b;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..

Oct 28 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.