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

Recommended Answers

All 2 Replies

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

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

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.