System.Data.OleDb.OleDbExc
Main Topics
Browse All TopicsHow 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
<%@ Import Namespace="System.Data.Ole
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql
<%@ Import Namespace="System.Configur
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Text.Reg
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Configur
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Secu
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.W
<%@ Import Namespace="System.Web.UI.W
<%@ Import Namespace="System.Web.UI.H
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtm
<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
Dim sConnectionString As String = "Provider=Microsoft.Jet.OL
& "Data Source=C:\Inetpub\wwwroot\
& ";" & "Extended Properties=Excel 8.0;"
' Create the connection object by using the preceding connection string.
Dim objConn As New OleDbConnection(sConnectio
' 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
' Build a table from the original data.
GridView1.DataSource = objDataset1.Tables(0).Defa
GridView1.DataBind()
'' Clean up objects.
objConn.Close()
End Sub
</script>
36
37 <html xmlns="http://www.w3.org/1
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>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: Juan_BarreraPosted on 2008-12-11 at 14:20:01ID: 23153061
Hi again,
You can display one workbook at the time this way. Otherwise, you'll need to merge them all.
By doing this:
"SELECT * FROM Sheet1$"
you are loading the workbook "Sheet1" only.
IS that what you want? What's the error you get?