Microsoft Jet 数据库引擎找不到对象'Sheet1$'请确定对象是否存在解决思路
Microsoft Jet 数据库引擎找不到对象'Sheet1$'。请确定对象是否存在
路径没错啊 里面有个Excel 有个teacher表格 什么原因啊? 我用的数据库是mysql
------解决思路----------------------
你的excel中Sheet名称是Sheet1吗?要是teacher,就写成teacher$
------解决思路----------------------
Sheet1$,你确定有这个名字,还是名字为 teacher
<form id="form1" runat="server">
<div id="container">
<asp:GridView ID="GridView1" BorderColor="Black"
OnRowDataBound="GridView1_RowDataBound" runat="server"
AutoGenerateColumns="False" Font-Size="12px" Width="560px" AllowSorting="True"
Height="154px">
<Columns>
<asp:BoundField DataField="编号" HeaderText="编号" />
<asp:BoundField DataField="姓名" HeaderText="姓名" />
<asp:BoundField DataField="性别" HeaderText="性别" />
<asp:BoundField DataField="所任课程" HeaderText="所任课程" />
</Columns>
<HeaderStyle BackColor="Azure" Font-Size="12px" HorizontalAlign="Center" />
<RowStyle HorizontalAlign="Center" />
<PagerStyle HorizontalAlign="Center" />
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="从 EXCEL 中 导 入 数 据" Height="34px" OnClick="Button1_Click" Width="326px" /></div>
</form>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using Commons;
using MySql.Data.MySqlClient;
using System.Drawing;
using System.IO;
using System.Text;
using System.Data.OleDb;
namespace TeachingAssistantSys
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
foreach (TableCell tc in e.Row.Cells)
{
tc.Attributes["style"] = "border-color:Black";
}
if (e.Row.RowIndex != -1)
{
int id = GridView1.PageIndex * GridView1.PageSize + e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
}
/// <summary>
/// Inport
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataSource = createDataSource();
GridView1.DataBind();
}
/// <summary>
/// 以Excel为数据源获取数据集
/// </summary>
/// <returns></returns>
private DataSet createDataSource()
{
string strCon;
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/Files/teacher.xls") + ";Extended Properties=Excel 8.0;";
OleDbConnection con = new OleDbConnection(strCon);
OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]", con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
}
路径没错啊 里面有个Excel 有个teacher表格 什么原因啊? 我用的数据库是mysql
------解决思路----------------------
你的excel中Sheet名称是Sheet1吗?要是teacher,就写成teacher$
------解决思路----------------------
Sheet1$,你确定有这个名字,还是名字为 teacher