|
-
Jun 28th, 2011, 05:21 AM
#1
Thread Starter
New Member
[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!
-
Jun 28th, 2011, 05:42 AM
#2
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.
-
Jun 28th, 2011, 05:50 AM
#3
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|