In my requirement, I am successfull in opening & reading Excel(both 2003 & 07) data from Asp.net OLEDB.
But it works only when Excel Sheet Kept open in our PC , Otherwise it gives 'External Table format error' .What exactly the problem ?.Can anyone show me light please. Is this anything problem with access rights?
Am sure Its nothing to do with connection string . My code
protected void Page_Load(object sender, EventArgs e)
{
string path = @"C:\Users\abcd\Desktop\raj.xls";
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + absoluteDir + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";
OleDbConnection oledbConn = new OleDbConnection(connStr);
try
{
oledbConn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
OleDbDataAdapter oleda = new OleDbDataAdapter();
oleda.SelectCommand = cmd;
DataSet ds = new DataSet();
oleda.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
catch (Exception err)
{
}
finally
{
// Close connection
oledbConn.Close();
}
}
Thanks in advance
Problem is with access problem .that mean sheet was password protected.