Link to home
Start Free TrialLog in
Avatar of jimseiwert
jimseiwertFlag for United States of America

asked on

VB.NET Add Row To DataSet

I have a gridview that i bound to a dataset. In my footer I have an option for add new row. When they click on that i run the below code it will add a row the way i want it to. If i run the code again it will remove the row it just added and reset the way the page originally loaded.

i am thinking i have to do something with the gridview to accept the changes before i read the datasource again

Any thoughts?
Dim packages As New DataSet
        packages = Me.GridView2.DataSource
 
        Dim packagerow As DataRow
 
        packagerow = packages.Tables(0).NewRow()
        packagerow(0) = "Package " & packages.Tables(0).Rows.Count + 1
        packagerow(1) = "1"
        packages.Tables(0).Rows.Add(packagerow)
 
        packages.AcceptChanges()
 
        Me.GridView2.DataSource = packages
        Me.GridView2.DataBind()
 
        packages = Nothing

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jfmador
jfmador
Flag of Canada 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
Thanks for the input