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,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    :| 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,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice