问题描述
我需要将Excel数据导入Asp.Net的Gridview中
当我这样做时,我遇到此错误:
Microsoft Jet数据库引擎找不到对象"qasim $".确保对象存在,并正确拼写其名称和路径名.
"qasim"是工作表名称,它存在于我的Excel工作表中.可能是什么问题呢.帮帮我.
I need to import Excel data into Gridview of Asp.Net
When i do that I am having this error:
The Microsoft Jet database engine could not find the object ''qasim$''. Make sure the object exists and that you spell its name and the path name correctly.
''qasim'' is a sheet name and it is present in my Excel sheet. What could be the problem. Help me.
public static OleDbConnection cnn2(string filename)
{
OleDbConnection cnn=new OleDbConnection();
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Sample1.xls;Extended Properties=Excel 8.0";
cnn.Open();
return cnn;
}
string SQLString ="SELECT * FROM" [产品$]";
OleDbCommand DBCommand =新OleDbCommand(SQLString,clsconnection.cnn2(filename));
IDataReader DBReader = DBCommand.ExecuteReader();
gvAttendence.DataSource = DBReader;
gvAttendence.DataBind();
string SQLString = "SELECT * FROM ''[Products$]''";
OleDbCommand DBCommand =new OleDbCommand(SQLString, clsconnection.cnn2(filename));
IDataReader DBReader = DBCommand.ExecuteReader();
gvAttendence.DataSource = DBReader;
gvAttendence.DataBind();
推荐答案
public static OleDbConnection cnn2(string filename)
{
OleDbConnection cnn=new OleDbConnection();
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Sample1.xls;Extended Properties=Excel 8.0";
cnn.Open();
return cnn;
}
string SQLString ="SELECT * FROM''[产品
string SQLString = "SELECT * FROM ''[Products
这篇关于将Excel数据导入Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!