Solved

VB.NET Add Row To DataSet

Posted on 2008-10-28
2
7,703 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:jimseiwert
2 Comments
 
LVL 5

Accepted Solution

by:
jfmador earned 500 total points
ID: 22828547
Hello, we use AcceptChanges after Updating your DataSet to your Database. If you use AcceptChanges after adding a row to your dataset your dataset schema won't know that this row was added, then it won't post it to your database.

Also you don't need to reset the datasource and databind, these are already set with your grid view. Adding a row to your table will automatically add the row to your datagrid

0
 
LVL 7

Expert Comment

by:EYoung
ID: 23471733
Thanks for the input
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question