1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

How to find a record from recordset?

Discussion in 'Visual Basic ( VB )' started by nadunalexander, May 4, 2007.

  1. nadunalexander

    nadunalexander New Member

    Joined:
    Sep 13, 2006
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    there is a recordset with name and address. name is primary key. I have to update some one address to his new address. How can i set cursor to the exact record without searching in all the records? I used while loop to set cursor. But it is very slow.

    This is my code
    Code:
    recordset.movefirst
    Do While Not recordset.EOF
                    If recordset.Fields(0).Value = txtName Then
                        recordset.Fields(1).Value = txtNewAddress
                        Exit Do
                    End If
                    recordset.MoveNext
     Loop
     
    Last edited by a moderator: May 4, 2007
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    :| select by the primary key and update it!
     
  3. nadunalexander

    nadunalexander New Member

    Joined:
    Sep 13, 2006
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Can u explain some more. I dont know database deeply
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Code:
    recordset.open oConn,"SELECT * FROM table WHERE primary_key=" & pValue
    
    if Not recordset.EOF
      recorset.Fields(1).Value = "something new"
      recordset.update
    end if
    
    something like this...
     
  5. nadunalexander

    nadunalexander New Member

    Joined:
    Sep 13, 2006
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Thank you for ur code. But my problem is not updating table. updating a recordset record that has more than one records
     

Share This Page