DataTable Population

RobEmDee

Well-known member
Joined
Mar 25, 2003
Messages
130
Location
Richmond, VA
I have read in several places (including MS Press "ADO.NET") that it is much more efficient to programmatically create the DataTables you need and then add them to the DataSet as opposed to having the DataAdapter create them for you. My question is, what would then be the most efficient way to populate the DataTables.....if they are already created, will the DataAdapter simply populate them and not effect the DataTable structure?
Thanks for your input.
 
Code:
Dim sconnstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source =" & strdatasource & ""
        Dim oledb As New OleDbConnection(sconnstring)

oledbdataadapter1 = New OleDbDataAdapter("SELECT somefields FROM sometable ORDER BY somefield ", oledb)
Dim olecmdbuilder1 As OleDbCommandBuilder
 olecmdbuilder1 = New OleDbCommandBuilder(oledbdataadapter1)
oledbdataadapter1.Fill(dataset1, "sometable")

This help?
 
Thank you for the response. I am describing creating the DataTable programmatically, adding it to the DataSet, and then retrieving the data from the db. Given my described scenario, if "sometable" is already instantiated in the DataSet, will filling it with the DataAdapter in the manner you described effect this pre-created structure?
 
The dataadapter provides a set of methods and properties to
retrieve and save data, forming a bridge between a data set and
its data source.
It encapsulates a set of data commands and a connection that is
used to fill a data set as well as to update the data source.
Code:
        Dim dtable As New DataTable()
        create dtable here
        Dim ds As New DataSet()

        Dim sel As New OleDbCommand("SELECT mydata, mynextcolumn FROM dtable")

        Dim da = New OleDbDataAdapter(sel)
        Dim olecmdbuilder1 As OleDbCommandBuilder
        olecmdbuilder1 = New OleDbCommandBuilder(da)
        da.Fill(ds, "Table1")
        Dim NewRow As DataRow = ds.Tables("Table1").NewRow
        NewRow("mydata") = "something"
        NewRow("mynextcolumn") = "thenextthing"
        ds.Tables("Table1").Rows.Add(NewRow)
        da.Update(ds, "Table1")

The above, treats your programatically created data table as a data source and then allows you to fill the dataset, manipulate the data and then update your data table.
 
Back
Top