gridview dataadapter.update


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: gridview dataadapter.update

  1. #1
    Join Date
    Jul 2007
    Posts
    3

    gridview dataadapter.update

    Hi all,

    Here is my problem: I have a small table to display in a gridview. The user needs to be able to edit any or all of the rows and save the data back to the database. I only want the user to have to click one update button for all the rows to update at once.

    Here is the code to bind the gridview to the appropriate data:
    _con = New SqlConnection(_myConString)
    _da = New SqlDataAdapter(_mySelectString", _con)
    _ds = New DataSet

    _da.Fill(_ds, "NOT")

    dgrTest.DataSource = _ds
    dgrTest.DataMember = "NOT"
    dgrTest.DataBind()

    The gridview populates nicely. Here is the code that executes when the user clicks the update button:
    Dim _cmb As New SqlCommandBuilder(_da)
    _da.Update(_ds.Tables(0))

    The problem is that a postback occurs when the update button is clicked, so my dataset becomes nothing as soon as that happens and the update fails because there is no table at index 0 of my dataset.

    I tried storing the dataset in a session variable right after binding it to the gridview and retrieving it when a postback occurs, but that just sets it back to the way it was before the user changed any rows, so the update succeeds but doesn't change any data.

    I hope I've explained this sufficiently to give you an idea of my problem. Thanks in advance for any help.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jul 2007
    Posts
    3

    Thanks

    Phil,

    Thanks for the speedy reply. The page you directed me to was good info and I made a note of it for future use. I was hoping for a little simpler solution, though. Any ideas?

Similar Threads

  1. ASP.NET 2 Textbox value in Gridview row
    By timmym in forum ASP.NET
    Replies: 8
    Last Post: 11-23-2008, 07:31 AM
  2. GridView Problem
    By Fafeman in forum ASP.NET
    Replies: 0
    Last Post: 05-02-2007, 12:58 PM
  3. Replies: 0
    Last Post: 04-02-2007, 10:39 AM
  4. Instantiating GridView programmatically
    By alphaoide in forum ASP.NET
    Replies: 1
    Last Post: 07-31-2006, 11:07 AM
  5. Replies: 0
    Last Post: 10-11-2005, 08:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center