将Excel数据导入Gridview [英] Excel Data into Gridview
问题描述
我需要将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();
推荐答案
''.确保该对象存在,并且正确拼写了它的名称和路径名.
"qasim"是工作表名称,它存在于我的Excel工作表中.可能是什么问题呢.帮帮我.
''. 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''[产品
string SQLString = "SELECT * FROM ''[Products
''";
OleDbCommand DBCommand =新OleDbCommand(SQLString,clsconnection.cnn2(filename));
IDataReader DBReader = DBCommand.ExecuteReader();
gvAttendence.DataSource = DBReader;
gvAttendence.DataBind();
''";
OleDbCommand DBCommand =new OleDbCommand(SQLString, clsconnection.cnn2(filename));
IDataReader DBReader = DBCommand.ExecuteReader();
gvAttendence.DataSource = DBReader;
gvAttendence.DataBind();
如何将Excel数据导入到gridview中.请添加一个小的代码片段进行查看.
从该错误看来,您好像定义了不带引号的工作表名称的名称,这使它看起来像一个变量.请检查.
How are you importing the excel data into gridview. Please add a small code snippet to look at.
From the error, it looks like you defined the name of the sheet name without quotes and that made it look like a variable. Kindly check.
这篇关于将Excel数据导入Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!