Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 1st, 2005, 11:10 AM
Registered User
 
Join Date: Oct 2004
Location: , , .
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?


Reply With Quote
  #2 (permalink)  
Old April 10th, 2005, 05:00 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,409
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?
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 03: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 12:06 PM



All times are GMT -4. The time now is 02:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.