[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

Populating a .net gridview from excel

Asked by soccerman777 in Programming for ASP.NET, Microsoft Visual Basic.Net

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="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
    <!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.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\po\book1.xls;Extended Properties=Excel 9.0;"
            Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
            & "Data Source=C:\Inetpub\wwwroot\QuickTrip20081211.xls" _
            & ";" & "Extended Properties=Excel 8.0;"
           

            ' Create the connection object by using the preceding connection string.
            Dim objConn As New OleDbConnection(sConnectionString)

            ' 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(objDataset1, "XLData")

            ' Build a table from the original data.
            GridView1.DataSource = objDataset1.Tables(0).DefaultView
            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>

 
Related Solutions
Keywords: Populating a .net gridview from excel
 
Loading Advertisement...
 
[+][-]12/11/08 03:13 PM, ID: 23153447Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Programming for ASP.NET, Microsoft Visual Basic.Net
Sign Up Now!
Solution Provided By: Juan_Barrera
Participating Experts: 1
Solution Grade: A
 
[+][-]12/11/08 02:20 PM, ID: 23153061Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/11/08 02:38 PM, ID: 23153212Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/22/09 03:55 PM, ID: 24455688Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_Related_20080208