We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,371 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Vb6 Update Query

help me update my database..
when i click edit it will add a new record..
i want to update a record..

to edit a new record it will be base on the cutsomer's nameu

Dim conn As ADODB.Connection
Dim RS As New ADODB.Recordset


Set conn = New ADODB.Connection

conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
            & "SERVER=localhost;" _
            & "DATABASE=database1;" _
            & "UID=root;" _
            & "PWD=;" _
            & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384
 
conn.CursorLocation = adUseClient
conn.Open


RS.Open "SELECT * from Phonebook", conn, adOpenStatic, adLockOptimistic
RS.Update
 
            txtName.Text = RS!Customers_Name
            RS!Address = txtAddress.Text
            RS!Mobile = txtMobile.Text
            RS!Telephone = txtTelephone.Text


RS.Update
MsgBox "Record has been Saved", vbInformation
RS.Close
conn.Close
2
Contributors
2
Replies
1 Hour
Discussion Span
1 Year Ago
Last Updated
5
Views
Question
Answered
Shodow
Junior Poster
167 posts since Jan 2011
Reputation Points: 14
Solved Threads: 0
Skill Endorsements: 0

Hi,

Change the code to :

To Add record:

RS.Open "SELECT * from Phonebook", conn, adOpenDynamic, adLockOptimistic
RS.AddNew
RS!Customers_Name = txtName.Text
RS!Address = txtAddress.Text
RS!Mobile = txtMobile.Text
RS!Telephone = txtTelephone.Text
RS.Update

To Edit the record:

RS.Open "SELECT * from Phonebook Where Customer_Name = '" & txtName.Text & "'", conn, adOpenDynamic, adLockOptimistic
If RS.EOF Then
    RS.AddNew   'Record Not Found so Adding New
    RS!Customers_Name = txtName.Text
Else
    RS.MoveFirst
End If
RS!Address = txtAddress.Text
RS!Mobile = txtMobile.Text
RS!Telephone = txtTelephone.Text
RS.Update

Regards
Veena

QVeen72
Veteran Poster
1,017 posts since Nov 2006
Reputation Points: 118
Solved Threads: 164
Skill Endorsements: 5

its working tnx but 1 more problem..
the saved record will be blank it wont show up the saved record you will add again the address,mobile and telephone number

Shodow
Junior Poster
167 posts since Jan 2011
Reputation Points: 14
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by QVeen72

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0600 seconds using 2.67MB