bhlabelle
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. FODBDataSe t.tblLette rs)
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!
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
Me.TblLettersTableAdapter.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Fine by me, nice you can resolve the problem
ASKER
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.
I had to make the Where clause:
Num = ?
And all was good.
I appreciate the assitance.
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.