Solved

VB.NET Add Row To DataSet

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now