Im new to Vb. I have created a simple database and its working fine. I want to implement a search function to my database. Iam also receiving an error when itry to edit a record. The error message reads you changes were not effected becaus ethey would create duplicate records. my code:

cmdedit_click

Rs!studentID=txtstudentID.text
Rs!lastname=txtlastname.text
Rs!firstname=txtfirstname.text
rs.update
end sub

studentID is the auto number and as well primary key

Recommended Answers

All 3 Replies

You need to check if the data already exists in database using COUNT before inserting the same to database.

You need to check if the data already exists in database using COUNT before inserting the same to database.

The data exists. Iam updating existing data, that is making changes to data in database table eg if my lastname was that I change it to this.

are you editing your primary key data also in your form along with other values and sending them as updated to the database?

if yes then avoid using that.
here your studentID is a primary key as well as autonumber field. so you can't update a primary key field as well as you cannot change its value because it is an autonumber field.

one more thing, always use the update statement instead of using the update method.

here is a sample :-

Dim conn as New ADODB.Connection

conn.connectionstring=<your connection string>
conn.open
conn.execute "update <your table name> set firstname='" & txtfirstname.text & "',lastname='" & txtlastname.text & "' where studentid='" & txtstudentid.text & "'"

hope this will help you.

regards
Shouvik

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.