%@ page language=c# autoeventwireup=true codefile=readexcel_cs.aspx.cs inherits=readexcel_cs % !doctype html public -//w3c//dtd xhtml 1.0 transitional//en http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd html xmlns=http
无标题页
------------------------------------- using system;
using system.data;
using system.configuration;
using system.collections;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
using system.data.oledb;
public partial class readexcel_cs : system.web.ui.page
{
public datatable dt;
protected void page_load(object sender, eventargs e)
{
//read excel file
string strconn;
strconn = provider=microsoft.jet.oledb.4.0; +
data source=c://test.xls; +
extended properties=excel 8.0;;
oledbdataadapter mycommand = new oledbdataadapter(select * from [sheet1$], strconn);
dataset mydataset = new dataset();
mycommand.fill(mydataset, excelinfo);
this.gridview1.datasource = mydataset.tables[excelinfo].defaultview;
this.gridview1.databind();
dt = (datatable)mydataset.tables[excelinfo];
/*
//read access file
string strconn2;
strconn2 = provider=microsoft.jet.oledb.4.0; +
data source=c://test.mdb; +
persist security info=true;;
oledbdataadapter mycommand2 = new oledbdataadapter(select * from test, strconn2);
dataset mydataset2 = new dataset();
mycommand2.fill(mydataset2, accessinfo);
this.gridview2.datasource = mydataset2.tables[accessinfo].defaultview;
this.gridview2.databind();
*/
}
protected void button1_click(object sender, eventargs e)
{
/*
//写入数据库david
for (int i = 1; i {
for (int j = 1; j {
string a = gridview1.rows[i].cells[j].tostring() ;
response.write(a.tostring() );
}
}
*/
for (int i = 0; i {
//for (int j = 0; j //{
string a=dt.rows[i][0].tostring();
string b= dt.rows[i][1].tostring();
string c = dt.rows[i][2].tostring();
string d = dt.rows[i][3].tostring();
string sqlinsert = insert test(a,b,c,d)values('+a+','+b+','+c+','+d+');
dataaccess.dataaccessshdb.getnonquery(sqlinsert.tostring());
//response.write(a.tostring()+,);
//}
}
}
}