How would I reference my data in my select statment. I tried Select * from [Sheet1$] that throws an error. I want to take the whole spreed sheet and drop it into a gridview.
<%@ Page Language="VB" %>
<%@ Register assembly="AjaxControlToolk
it" namespace="AjaxControlTool
kit" tagprefix="cc1" %>
<%@ Import Namespace="System.Data.Ole
Db" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql
Client" %>
<%@ Import Namespace="System.Configur
ation" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Text.Reg
ularExpres
sions" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Configur
ation" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Secu
rity" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.W
ebControls
" %>
<%@ Import Namespace="System.Web.UI.W
ebControls
.WebParts"
%>
<%@ Import Namespace="System.Web.UI.H
tmlControl
s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Create variables that are used in code sample.
Dim i, j As Integer
' Create connection string variable. Modify the "Data Source" parameter as
' appropriate for your environment.
' Dim sConnectionString As String = "Provider=Microsoft.Jet.OL
EDB.4.0;Da
ta Source=C:\Inetpub\wwwroot\
po\book1.x
ls;Extende
d Properties=Excel 9.0;"
Dim sConnectionString As String = "Provider=Microsoft.Jet.OL
EDB.4.0;" _
& "Data Source=C:\Inetpub\wwwroot\
QuickTrip2
0081211.xl
s" _
& ";" & "Extended Properties=Excel 8.0;"
' Create the connection object by using the preceding connection string.
Dim objConn As New OleDbConnection(sConnectio
nString)
' Open connection with the database.
objConn.Open()
' The code to follow uses a SQL SELECT command to display the data from the worksheet.
' Create new OleDbCommand to return data from worksheet.
Dim objCmdSelect As New OleDbCommand("SELECT * FROM Sheet1$", objConn)
' Create new OleDbDataAdapter that is used to build a DataSet
' based on the preceding SQL SELECT statement.
Dim objAdapter1 As New OleDbDataAdapter()
' Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect
' Create new DataSet to hold information from the worksheet.
Dim objDataset1 As New DataSet
' Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(objDatase
t1, "XLData")
' Build a table from the original data.
GridView1.DataSource = objDataset1.Tables(0).Defa
ultView
GridView1.DataBind()
'' Clean up objects.
objConn.Close()
End Sub
</script>
36
37 <html xmlns="
http://www.w3.org/1999/xhtml"
>
38 <head id="Head1" runat="server">
39 <title>Untitled Page</title>
40 </head>
41 <body>
42 <form id="form1" runat="server">
43 <div>
44 <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 100; left: 23px; position: absolute;
45 top: 47px"></asp:TextBox>
46 <asp:GridView ID="GridView1" runat="server">
</asp:GridView>
47
48 </div>
49 </form>
50 </body>
51
</html>