updating datagridview in vb 2005


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: updating datagridview in vb 2005

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Posts
    4

    updating datagridview in vb 2005

    i have a datagridview that gets it's data from a MS access 2003 database via a table adapter. the datagridview shows the data fine on load, however, it is there for viewing purposes only, and not editing. the editing is done via code...the only problem is, i do not know how to update the datagridview after i have changed the databse via code. If i stop and start the program again, on load the datagridview fills with the data.

    anyone know how this is done?

    call this does not work:

    Code:
    Me.FactoryAQueueTableAdapter.Fill(Me.myDBDataSet.FactoryAQueue)

  2. #2
    Join Date
    Dec 2004
    Posts
    61
    I'm sorry i don't know what to do with vb again 'cause i'm using c#.
    But this codes below will be not much different with vb.

    Code:
        
        /***
          Before you can update the dataSet make sure you
          call the EndEdit() method from the dataSet or from your 
          BindingSource.
       */
         this.BindingContext[dataSet, "Table1"].EndEdit();
    
        /*** 
          You can just call the Update() method from dataAdapter which
          receives one parameter that is the dataSet but you will always
          have concurrency exception raised.
        */
        DataSet dsToUpdate = dataSet.Table1.GetChanges();
        if (dsToUpdate != null) {
            dataAdapter.Update(dsToUpdate);
        }
    
         /*** 
          This is the most safe way i think to update dataSet.
          You update the dataSet by three steps.
          We will use Select() method from dataSet which will return DataTable.
          The Select() method receives three parameters that are
          filterCriteria, sortCriteria, and DataRowViewState respectively.
          If you don't want to add any filter or sort just put null.
        */
        if (dataSet.HasChanges()) {
            dataAdapter.Update(dataSet.Table1.Select(null, null, DataViewRowState.Deleted));
            dataAdapter.Update(dataSet.Table1.Select(null, null, DataViewRowState.Added));
            dataAdapter.Update(dataSet.Table1.Select(null, null, DataViewRowState.ModifiedCurrent));
        }
    
        /*** 
          After the dataset have been updated you must call the
          AcceptChanges() method from the dataSet so the ModifiedCurrent
          state record will be changed to Original state means that all of
          your changes is commited.
        */
         dataSet.Table1.AcceptChanges();
    
    /***
    
    References:
    
    +---------------------|---------------+
    +   vb                       |       c#          +
    +---------------------|---------------+
    +   Me                      |      this           +
    +   () for array           |       []            +
    +  if ..... End If           |   if (.....) { }   +
    +---------------------|---------------+
    
    **/
    Hope will help you out .

    me_code2004.
    Last edited by me_code2004; 06-20-2006 at 10:46 AM.

Similar Threads

  1. Replies: 6
    Last Post: 01-02-2007, 09:41 PM
  2. VB 2005 - Inserting Values to DB
    By TigerMoonSix in forum .NET
    Replies: 4
    Last Post: 06-15-2006, 07:06 PM
  3. .NET vs. Enterprise Java: Who's Got Better Security?
    By Glen Kunene in forum Talk to the Editors
    Replies: 17
    Last Post: 03-23-2002, 12:43 AM
  4. Replies: 90
    Last Post: 04-17-2001, 12:45 AM
  5. Updating an online database through a VB program
    By Nick Jones in forum VB Classic
    Replies: 2
    Last Post: 03-20-2000, 10:07 PM

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