?
Solved

ASPX Import excel spreadsheet into SQL 2005

Posted on 2009-12-28
6
Medium Priority
?
307 Views
Last Modified: 2013-11-26
I am developing in Visual Studio 2008 and trying to get data from an excel spreadsheet imported into an sql 2005 table.  I was able to accomplish this in a vb.net application by using the method in this link http://vb.net-informations.com/excel-2007/vb.net_excel_oledb.htm but I cannot figure out how to make it work in my web application.
0
Comment
Question by:schwientekd
  • 4
  • 2
6 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 26131781
it should be the same code bascially...where are your problems at?
0
 

Author Comment

by:schwientekd
ID: 26132263
Here is the code I am using but when it runs the gridview does not appear on the page?
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Try
            Dim MyConnection As System.Data.OleDb.OleDbConnection
            Dim DtSet As System.Data.DataSet
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
            MyConnection = New System.Data.OleDb.OleDbConnection _
            ("provider=Microsoft.Jet.OLEDB.4.0; Data Source='C:\TestFile.xls'; Extended Properties=Excel 8.0;")
            MyCommand = New System.Data.OleDb.OleDbDataAdapter _
                ("select * from [Sheet1$]", MyConnection)
            MyCommand.TableMappings.Add("Table", "TestTable")
            DtSet = New System.Data.DataSet
            MyCommand.Fill(DtSet)
            GridView1.DataSource = DtSet.Tables(0)
            MyConnection.Close()

            Button2.Enabled = True

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub

Open in new window

0
 
LVL 21

Accepted Solution

by:
silemone earned 2000 total points
ID: 26132358
you need to add the line

GridView1.DataBind();
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:silemone
ID: 26132373
i will update the code...otherwise if my change doesn't produce a table, the grid's not getting data and you will have to debug why with breakpoints.
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Try
            Dim MyConnection As System.Data.OleDb.OleDbConnection
            Dim DtSet As System.Data.DataSet
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
            MyConnection = New System.Data.OleDb.OleDbConnection _
            ("provider=Microsoft.Jet.OLEDB.4.0; Data Source='C:\TestFile.xls'; Extended Properties=Excel 8.0;")
            MyCommand = New System.Data.OleDb.OleDbDataAdapter _
                ("select * from [Sheet1$]", MyConnection)
            MyCommand.TableMappings.Add("Table", "TestTable")
            DtSet = New System.Data.DataSet
            MyCommand.Fill(DtSet)
            GridView1.DataSource = DtSet.Tables(0)
            GridView1.DataBind()
            MyConnection.Close()

            Button2.Enabled = True

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub

Open in new window

0
 

Author Closing Comment

by:schwientekd
ID: 31670415
That did the trick.  Thanks alot!
0
 
LVL 21

Expert Comment

by:silemone
ID: 26132398
great!

Happy programmings and holidays.


cheers.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question