Link to home
Start Free TrialLog in
Avatar of bhlabelle
bhlabelleFlag for Afghanistan

asked on

vb.net tableadapter update command

I do not know how to write an update command, and could use some help.

I have a datagridview that is linked to an access database. The table is "tblLetters", and the fields are "Descr", "Sent", "Return", "Rec", "Notes"

In the DataGridView1_CellEndEdit routine I have the following code:
Me.Validate()
Me.TblLettersBindingSource.EndEdit()
Me.TblLettersTableAdapter.Update(Me.FODBDataSet.tblLetters)

In the DataSet tblLettersTableAdapter I have the following Command Text in the Update Command:
UPDATE       tblLetters
SET                Descr = ?, Sent = ?, Return = ?, Rec = ?, Notes = ?

Now I know this is wrong, and if you are interested in knowing what this does, well whatever record you make the update on, lets say letter #5, now becomes the record for every letter.  Instead of having letters 1-10, you now have 10 letters that all have the same information as letter #5.  As you can tell, I'm not a programmer, more of a hack just trying to write a small program for our admin people.  

There is no primary key in the tblLetters, not sure if I need to have one or not.

Hopefully I haven't left anything out.  Thanks for any assitance!
SOLUTION
Avatar of gamarrojgq
gamarrojgq

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bhlabelle

ASKER


I made the Descr the Primary Key in my Access DB, and I added the following Where clause:
UPDATE       tblLetters
SET                Descr = ?, Sent = ?, Return = ?, Rec = ?, Notes = ?
WHERE        (Descr = Descr)

However, when I try to update a record I get the following error message:
The changes you requested to the table were not successful because they would create values in the index, primary key, or relationship.  Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

Seems like my vb application is still doing the same thing, but now Access is not permiting copying the same record multiple times since there is a primay key.
SOLUTION
Avatar of Shahan Ayyub
Shahan Ayyub
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gamarrojgq
gamarrojgq

Fine by me, nice you can resolve the problem
I awarded points to both, a few more to the first response, hope that is ok with you two.

I had to make the Where clause:
Num = ?

And all was good.  

I appreciate the assitance.