?
Solved

VB.NET Add Row To DataSet

Posted on 2008-10-28
2
Medium Priority
?
7,721 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
jfmador earned 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

741 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