<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div align="center"> <table style="position: relative"> <tr> <td style="height: 21px; padding-left: 5px;" colspan="2" align="left"> Customer Information.....</td> </tr> <tr> <td style="padding-left: 5px; height: 21px;" align="left"> Name:</td> <td style="padding-left: 5px; height: 21px;" align="left"> <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox></td> </tr> <tr> <td style="padding-left: 5px; height: 21px;" align="left"> Address</td> <td style="padding-left: 5px; height: 21px;" align="left"> <asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox></td> </tr> <tr> <td style="padding-left: 5px; height: 21px;" align="left"> </td> <td style="padding-left: 5px; height: 21px;" align="left"> <asp:Button ID="Button1" runat="server" Text="Submit" /> <asp:Button ID="Button2" runat="server" Style="position: relative" Text="Reset" /></td> </tr> </table> </div> <br /> <br /> <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Style="position: relative" Width="125px"> </asp:DetailsView> </form></body></html>
Imports System.DataImports System.Data.DataSetImports System.Data.OleDbImports System.Data.SqlClientPartial Class test Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click ' Connect to the Excel Spreadsheet Dim ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & Server.MapPath("CustomerInformation.xls") & ";" & _ "Extended Properties=Excel 5.0;" ' create your excel connection object using the connection string Dim objXConn As New OleDbConnection(ConnStr) objXConn.Open() ' use a SQL Select command to retrieve the data from the Excel Spreadsheet ' the "table name" is the name of the worksheet within the spreadsheet ' in this case, the worksheet name is "Members" and is coded as: [Members$] Dim objCommand As New OleDbCommand("SELECT * FROM [Sheet1$]", objXConn) Dim objOledbDataAdapter As New OleDbDataAdapter() objOledbDataAdapter.SelectCommand = objCommand Dim objDataset As New DataSet() objOledbDataAdapter.Fill(objDataset, "XLDATA") DetailsView1.DataSource = objDataset.Tables(0).DefaultView DetailsView1.DataBind() objXConn.Close() End SubEnd Class