Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

create new dataset using an existing one

My dataset has all of these columns : username, accountnumber, first_last_name, phonenumber
I want to create a new dataset which has only two column : username, ref_account. What am I doing wrong below?
Public Function Modify_dataset_test(ByVal ds_tmp As DataSet) As DataSet
        Dim ds As New DataSet
        Dim dt As DataTable
        Dim dr As DataRow
        dt = New DataTable
         dt.Columns.Add("username")
        dt.Columns.Add("ref_account")
        dr = dt.NewRow
        For Each ds_str As DataRow In ds_tmp.Tables(0).Rows
            dt.Rows.Add(ds_str.Item("username"))
            dt.Rows.Add(ds_str.Item("account_number") & " : " & ds_str.Item("first_last_name") & " " & ds_str.Item("phonenumber"))
        Next
        ds.Tables.Add(dt)
 
        Return ds
 
    End Function
Avatar of james-ct16
james-ct16
Flag of Australia image

Howdy

You are trying to add your column values as new rows in the second data table opposed to adding a new row.
It should be something like the following

 For Each ds_str As DataRow In ds_tmp.Tables(0).Rows
 dr = dt.NewRow
           dr("username") = (ds_str.Item("username"))
           dr("ref_account")=(ds_str.Item("account_number") & " : " & ds_str.Item("first_last_name") & " " & ds_str.Item("phonenumber"))
dt.rows.add(dr)
        Next

Hope that helps
SOLUTION
Avatar of Gerry Bartley
Gerry Bartley
Flag of Ireland 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
Avatar of YZlat
YZlat
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