dim myoledbconnection as oledbconnection = new oledbconnection("provider=microsoft.jet.oledb.4.0;" & _ "data source=c:/test.xls;" & _ "extended properties=""excel 8.0;""") dim myoledbcommand as oledbcommand = new oledbcommand("select * from [sheet1$]",myoledbconnection) '如果你想读出sheet2的内容 ,把sheet1$改成sheet2$即可 dim mydata as oledbdataadapter= new oledbdataadapter(myoledbcommand)
dim mydataset as new dataset() mydata.fill(mydataset) '完成从oledbdataadapter对象到dataset的转换 datagrid1.datasource = mydataset.tables(0).defaultview datagrid1.databind() '完成数据帮定,显示数据
四. 具体的源代码:
<%@ page language="vb" %> <%@ import namespace="system.data" %> <%@ import namespace="system.data.oledb" %> <script language="vb" runat="server"> sub page_load(sender as object, e as eventargs) dim mydataset as new dataset() dim myoledbconnection as oledbconnection = new oledbconnection("provider=microsoft.jet.oledb.4.0;" & _ "data source=c:/2.xls;" & _ "extended properties=""excel 8.0;""") dim myoledbcommand as oledbcommand = new oledbcommand("select * from [sheet1$]",myoledbconnection) dim mydata as oledbdataadapter= new oledbdataadapter(myoledbcommand)
mydata.fill(mydataset)
datagrid1.datasource = mydataset.tables(0).defaultview datagrid1.databind() end sub </script>