asp教程.net c# 读取excel数据代码
public dataset exceltods(string path)
{
string con = "provider=microsoft.jet.oledb.4.0;data source="+"e:collegemisupexcel" + fileupload1.filename+";extended properties='excel 8.0;imex=1'";
oledbconnection olecon = new oledbconnection(con);
oledbdataadapter oleda = new oledbdataadapter("select * from [sheet1$]", con);//sheet1是sheet的名字
string strexcel = "";
oledbdataadapter mycommand = null;
dataset ds = null;
//从excel的一个工作表中导入数据到数据库教程中
strexcel = "select 门牌号,用户名,用户人口数目,用户住房面积,用户取暖面积,用户电话,用户工作单位,用户数据类型 from [sheet1$]";
try
{
mycommand = new oledbdataadapter(strexcel, strconn);
ds = new dataset();
mycommand.fill(ds, "table1");
}
catch(exception e)
{
conn.close();
mycommand.dispose();
}
return ds;
}
//sheet1是sheet的名字