Solved

VB.NET Add Row To DataSet

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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 …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

13 Experts available now in Live!

Get 1:1 Help Now