Link to home
Start Free TrialLog in
Avatar of bertino12
bertino12

asked on

Fill dataset table

I have a dataset that I have created earlier like this:

Public Sub Main()
    dim ds as dataset
    ds  = buildDS()
    getCars(ByVal ds As DataSet)
End Sub

Private Function buildDS() As DataSet
        Dim ds As DataSet = New DataSet("DS")
        ds.Tables.Add(CreateCarTable)
        Return ds
End Function

Private Function CreateCarTable() As DataTable
        Dim dt As DataTable = New DataTable("Cars")
        dt.Columns.Add(New DataColumn("Manufacturer", GetType(String)))
        dt.Columns.Add(New DataColumn("Model", GetType(String)))
        Return dt
End Function

I call a function that executes SQL for me and it adds the data to the dataset  --> ds.tables(0), but I want to copy the data to the datasets table I created earlier. -->   ds.tables("Cars")  
How can I make sure this select statement goes into the table, ds.tables("Cars"), that I created earlier and not just to ds.tables(0) ??

        Public Function getCars(ByVal ds As DataSet)
            Dim sSQL As String = "SELECT MANUFACTURER, MODEL FROM CARS"
            ds = OracleHelper.ExecuteDataset(AppSettings.ConnectionString, CommandType.Text, sSQL, Nothing)
            return ds
        End Function

Thanks for your time
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

"How can I make sure this select statement goes into the table, ds.tables("Cars"), that I created earlier and not just to ds.tables(0) ??"
All you have to do is in debug mode  break on this table and go and read what is in them.
You will see from the data if you are reading the correct table to table data.
Avatar of bertino12
bertino12

ASKER

I did that and ds.tables("Cars") has nothing, but ds.tables(0) has the value. How can I put the table into ds.tables("Cars") instead?
Im looking for a way not to have to resort to iterating through the ds.tables(0) and copying the contents to ds.tables("Cars"). I would like to just copy the select statements table directly to ds.tables("Cars")
SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial