estblishing a conection of a excel sheet with C# application
-
i m trying to connecting the excel sheet with C# application but getting the error "External table is not in the expected format." i have written the following lines of code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.OleDb;public partial class excelform : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Create connection string variable. Modify the "Data Source"
// parameter as appropriate for your environment.
string conn = ("Provider=Microsoft.Jet.OLEDB.4.0;" +
("Data Source=" + Server.MapPath("excelsht.xlsx") +
// or use instead of Excel 8.0 - Excel 5.0
";Extended Properties=\"Excel 8.0;\""));
string SSQL = "SELECT * from [excelsht$]";// here use oleDataReader OleDbDataAdapter oleDA = new OleDbDataAdapter(SSQL, conn); DataSet ds = new DataSet(); oleDA.Fill(ds); GridView1.DataSource = ds.Tables\[0\].DefaultView; GridView1.DataBind(); }
}
-
i m trying to connecting the excel sheet with C# application but getting the error "External table is not in the expected format." i have written the following lines of code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.OleDb;public partial class excelform : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Create connection string variable. Modify the "Data Source"
// parameter as appropriate for your environment.
string conn = ("Provider=Microsoft.Jet.OLEDB.4.0;" +
("Data Source=" + Server.MapPath("excelsht.xlsx") +
// or use instead of Excel 8.0 - Excel 5.0
";Extended Properties=\"Excel 8.0;\""));
string SSQL = "SELECT * from [excelsht$]";// here use oleDataReader OleDbDataAdapter oleDA = new OleDbDataAdapter(SSQL, conn); DataSet ds = new DataSet(); oleDA.Fill(ds); GridView1.DataSource = ds.Tables\[0\].DefaultView; GridView1.DataBind(); }
}