Results 1 to 3 of 3

Thread: [RESOLVED] Insert, Update & Delete Records in Datagridview

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    15

    Resolved [RESOLVED] Insert, Update & Delete Records in Datagridview

    Hello.

    I'm creating a project using Microsoft Access 2007 & Visual Basic 2008.
    I have two tables in my database, Staff and Training Attended. The Training Attended records of Staff are displayed in datagridview, residing in a different form from the Staff details.

    What my program does is, it will display all of the Staff's list of Training Attended in datagridview once I click the button in Staff form. I've succeeded in retrieving the records. using
    Code:
    bindingsource.filter
    The problem is that I can't insert/update/delete records in the Training Attended datagridview. it keep giving me this error:
    Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

    How can i solve my problem?? is there any way to do this using table adapter, bindingsource or something without using Ole.DB or SQL??

    Your help is very much appreciated. thanks!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Insert, Update & Delete Records in Datagridview

    That means that the system didn't generate a SQL UPDATE statement when it created the TableAdapter that would happen for one of the following reasons:

    1. The table doesn't have a primary key.
    2. The query doesn't return the primary key.
    3. The query joins two or more tables.

    Rectify the issue, re-run the configuration wizard and an UpdateCommand will be generated. If you aren't able to change the condition that caused the issue for some reason, e.g. you need to join multiple tables, then you can add the UpdateCommand to the TableAdapter yourself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    15

    Re: Insert, Update & Delete Records in Datagridview

    Apparently i've set the primary key in VB's Dataset designer instead of setting it in Access beforehand. So, i've opened my Access, set the primary key and refresh my data sources in VB and it works!

    thanks! you're a life saver

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width