Create DataTable

chrisryhal used Ask the Experts™
I am using an SDK with an ERP system that allows me to make use of SQL Views that are canned within the application.  I declare the view like so:

Dim edvCurrentWork As EpiDataView = CType(oTrans.EpiDataViews("CurrentWork"), EpiDataView)

I need to take this view I declared and bound the results to a DataTable to be able to make use of later on with a MERGE option.  Ultimate goal would would be have 2 of these "EpiDataView"s and merge them together to bound the data to a native .NET 2.0 datagrid.

Any help with how to use this dataview and bound it to a DataTable would be VERY much appreciated as there is no connection string, etc becaue the view and the data is essentially already there if that makes sense.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dirk HaestProject manager
Populate Data from data table
public class MainClass
   Shared Sub Main()
      Dim thisConnection As New SqlConnection("server=(local)\SQLEXPRESS;" & _
          "integrated security=sspi;database=MyDatabase")
      'Sql Query
      Dim sql As String = "SELECT * From Employee"
         ' Open Connection
         Console.WriteLine("Connection Opened")
         ' Create Data Adapter
         Dim da As New SqlDataAdapter(sql, thisConnection)
         ' Create and fill Dataset
         Dim ds As New DataSet
         da.Fill(ds, "Employee")
         ' Get Data Table
         Dim dt As DataTable = ds.Tables("Employee")
         'Display Data
         For Each row As DataRow In dt.Rows
            For Each col As DataColumn In dt.Columns
            Console.WriteLine("".PadLeft(20, "="))
      Catch ex As SqlException
         ' Display error
         Console.WriteLine("Error: " & ex.ToString())
         ' Close Connection
         Console.WriteLine("Connection Closed")
      End Try
   End Sub
End Class

Open in new window


May have posted this as I was editing my question.  There is no "connection string" involved as the connection is already opened.  So if "SqlDataAdapter" requires  2 params this won't work.  Essentially the hard part in my eyes is does, its just bounding the datatable with the view.  
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Top Expert 2007
If it is an actual .NET DataView, then it should have a .Table property that exposes the DataTable that the view represents.

Dim table As DataTable = edvCurrentWork.Table

'Use table as you want...

Top Expert 2007
Additionally, you have be able to bindingsource

    Dim bs As New BindingSource()
    bs.DataSource = edvCurrentWork

    Me.DataGridView.DataSource = bs

Or, you may have to create a new DataTable programmatically, then loop through each row in the view to populate the table.

    Dim table As New DataTable()

    'Loop through each row in the view...
    For Each row As Object in edvCurrentWork    'or edvCurrentWork.Rows (whatever)

        Dim r As DataRow = table.NewRow()

        r.Item("Column1") = r("Column1")  'however it's exposed



    Me.DataGridView.DataSource = table
Most Valuable Expert 2012
Top Expert 2014
You need to explore the EpiDataView class. What methods and properties it provides? Does it inherit from some native .NET class  (such as DataView)?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial