Solved

VB.NET Add Row To DataSet

Posted on 2008-10-28
2
7,698 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

770 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