Note that there are some explanatory texts on larger screens.

plurals
  1. PORaise event upon population of DataTable
    text
    copied!<p>I have a Form in which I have to populate DataGrid. The source for this DataGrid comes from another class.</p> <p>I need to populate the DataGrid through Raising Event in that class in which i'm getting Datatable.</p> <pre><code>Imports System.IO Public Class ExcelReader Private WithEvents tmrRead As New Timer Dim fullpath As String = "" Public Sub ExcelReader() tmrRead.Interval = 2000 tmrRead.Start() End Sub Public Sub TimerTick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrRead.Tick Dim DT As New DataTable Dim path As String = Directory.GetParent(Directory.GetParent(Directory.GetCurrentDirectory).ToString).ToString + "\ExcelHotReader\" Dim file1 As String() = System.IO.Directory.GetFiles(path, "*.xls") Dim file2 As String() = System.IO.Directory.GetFiles(path, "*.xlsx") If file1.Count &lt;&gt; 0 Or file2.Count &lt;&gt; 0 Then tmrRead.Stop() End If If file1.Count &lt;&gt; 0 Then fullpath = file1(0).ToString End If If file2.Count &lt;&gt; 0 Then fullpath = file2(0).ToString End If Dim DT As New DataTable Dim cn As System.Data.OleDb.OleDbConnection Dim cmd As System.Data.OleDb.OleDbDataAdapter cn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" &amp; "data source=" &amp; fullpath &amp; ";Extended Properties=Excel 8.0;") cmd = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", cn) cn.Open() cmd.Fill(DT) cn.Close() End Sub End Class </code></pre> <p>After cn.Close() the event should be raised with Datatable. This event need to be captured by the form to populate DataGrid.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload