PDA

View Full Version : سوال: نمایش ستونها یک Sheet فایل اکس در کنترل گریدویو



majid.mp
شنبه 17 تیر 1391, 11:21 صبح
با سلام
دوستان من یک فایل اکسل دارم که درون آن یک Sheet وجود دارد در Sheet مذکور چهار ستون وجود دارد حال من میخوام این ستون ها را در یک کنترل گرید ویو نمایش دهم کدهای خود را به صورت زیر نوشتم:

protected void Page_Load(object sender, EventArgs e) {
string connString = ConfigurationManager.ConnectionStrings["xls"].ConnectionString;
// Create the connection object
OleDbConnection oledbConn = new OleDbConnection(connString);
try
{
// Open connection
oledbConn.Open();

// 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.
oleda.Fill(ds, "Employees");

// Bind the data to the GridView
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
catch
{
}
finally
{
// Close connection
oledbConn.Close();
}

}

اما در هنگام اجرا پیغام خطای :
External table is not in the expected format

را دریافت میکنم!
دوستان لطفاً بفرمایید مشکل از کجاست؟
با تشکر