Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 1st, 2005, 12:10 PM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding new rows to Datagrid

Hi all,
I am using an ASP.net datagrid to perform various modifications and update to an sql table.

This grid was created the same way it was specified in the
MSDN`s: Walkthrough: Using a DataGrid Web Control to Read and Write Data article.

The grid does not support adding new rows by default, so the article improvised a way by adding a row to the datasource(in my case the dataset) and rebind the data grid then set the newly added row to edit mode. So if my dataset initially contained two records, now it contains three! So far so good

But at some point the users decides to cancel the new row without typing anything inside the fields. T the cancel operation does not know that the new row is , well new, so it simply set the edit Index to -1 which forces the field to turn to labels even when it is still empty.

Now this is where it gets a little weird. Suppose that the user clicks on the add button again, the same operation of adding to datasource rebinding etc... Take effect again so now my Datasource contains four records instead of there. The moment the user hits the update the two new records are added to the database, remember there is a record that was canceled.

In order to avoid this problem I decided to refill my dataset using
sqlDataAdapter.fill(dataset). Which it is supposed to refresh the datasource from the database. In other words I am re-querying the database so I can get a clean dataset. Only this part is not working. No matter what I do I always, end up with the Dataset with the four records. Any Ideas?


 
Old April 10th, 2005, 05:00 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If Cancel is being pressed, then you shouldn't be updating the database. Is this happening? Does the database reflect a change when there shouldn't be one?





Similar Threads
Thread Thread Starter Forum Replies Last Post
adding all the rows to get a total value KeviJay SQL Language 2 May 29th, 2008 03:22 AM
Problem with adding rows to database gule2902 Visual Basic 2005 Basics 4 September 13th, 2007 05:10 PM
Dynamically adding DataGrid rows lepreston ASP.NET 1.x and 2.0 Application Design 3 November 22nd, 2006 04:33 AM
Adding customised rows to datagrid danielg C# 2 April 11th, 2005 05:35 PM
adding rows to datatable forkhead ADO.NET 2 March 18th, 2004 01:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.