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..
Thanks alot!vb.net Code:
Imports System.Data Imports System.Data.OleDb Partial Class _Default Inherits System.Web.UI.Page Protected Sub btnGenerate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGenerate.Click If fu_Load.HasFile Then LoadSheets() End If End Sub Private Sub LoadSheets() Dim Con As New OleDb.OleDbConnection Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fu_Load.HasFile & ";Extended Properties=""Excel 8.0;HDR=No;""" Try Con.Open() Dim DT As New DataTable("Sheets") DT = Con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing) ' Clear controls in placeholder PH.Controls.Clear() ' Add controls For Each Row As DataRow In DT.Rows Dim Control As DGControl = LoadControl("DGControl.ascx") ' Set Name Control.TabName = Row.Item("Table_Name") ' Set Data Control.Data = Get_ExcelData(Con, Row.Item("Table_Name")) PH.Controls.Add(Control) PH.Controls.Add(New LiteralControl("<br />")) Next Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Function Get_ExcelData(ByVal Con As OleDb.OleDbConnection, ByVal SheetName As String) As DataTable Dim DT As New DataTable("Data") Dim DA As New OleDbDataAdapter("Select * from [" & SheetName & "]", Con) DA.Fill(DT) Return DT End Function End Class
---Jhimz




Reply With Quote