954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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
Shodow
Junior Poster
115 posts since Jan 2011
Reputation Points: 14
Solved Threads: 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
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

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
115 posts since Jan 2011
Reputation Points: 14
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: