Results 1 to 7 of 7

Thread: [RESOLVED] What's wrong with my code??

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    11

    Resolved [RESOLVED] What's wrong with my code??

    Hi..

    Im trying to upload an excel file and generate it in datagrid. When I clicked the button generate, nothing has been populated. Can you take a look at my code and check it please..
    vb.net Code:
    1. Imports System.Data
    2. Imports System.Data.OleDb
    3.  
    4. Partial Class _Default
    5.     Inherits System.Web.UI.Page
    6.  
    7.     Protected Sub btnGenerate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
    8.         If fu_Load.HasFile Then
    9.             LoadSheets()
    10.         End If
    11.     End Sub
    12.  
    13.     Private Sub LoadSheets()
    14.         Dim Con As New OleDb.OleDbConnection
    15.         Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fu_Load.HasFile & ";Extended Properties=""Excel 8.0;HDR=No;"""
    16.  
    17.         Try
    18.             Con.Open()
    19.  
    20.             Dim DT As New DataTable("Sheets")
    21.             DT = Con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
    22.  
    23.             ' Clear controls in placeholder
    24.             PH.Controls.Clear()
    25.  
    26.             ' Add controls
    27.             For Each Row As DataRow In DT.Rows
    28.                 Dim Control As DGControl = LoadControl("DGControl.ascx")
    29.  
    30.                 ' Set Name
    31.                 Control.TabName = Row.Item("Table_Name")
    32.  
    33.                 ' Set Data
    34.                 Control.Data = Get_ExcelData(Con, Row.Item("Table_Name"))
    35.  
    36.                 PH.Controls.Add(Control)
    37.                 PH.Controls.Add(New LiteralControl("<br />"))
    38.             Next
    39.  
    40.         Catch ex As Exception
    41.             MsgBox(ex.Message)
    42.         End Try
    43.     End Sub
    44.  
    45.     Private Function Get_ExcelData(ByVal Con As OleDb.OleDbConnection, ByVal SheetName As String) As DataTable
    46.         Dim DT As New DataTable("Data")
    47.         Dim DA As New OleDbDataAdapter("Select * from [" & SheetName & "]", Con)
    48.         DA.Fill(DT)
    49.  
    50.         Return DT
    51.     End Function
    52. End Class
    Thanks alot!

    ---Jhimz
    Last edited by Hack; Oct 20th, 2009 at 06:54 AM. Reason: Added Highlight Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width