VB6 wih SQL 2005

Posted on 2011-04-27
Last Modified: 2012-05-11
if i run this code in vb6 to remove few rows from the SQL2005 database, its entering in to a unstoppable loop. Please help me to resolve this

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

conn.Open "Provider = sqloledb;" & "Data Source=;" & "Initial Catalog=Master;" & "User ID=sa;" & "Password=password;"
rs.Open "select * from applications", conn, adOpenStatic, adLockOptimistic, adCmdText

Do Until rs.EOF
If rs.Fields(1) = HID Then

End If

All other connectivity with the same connection is working fine. While trying to delete this problem occurs..

Question by:Intelops

    Author Comment

    HID value i am getting from other one query..
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    would it be possible to combine the 2 queries:

    DELETE applications
      WHERE HID in ( SELECT HID FROM othertable WHERE ... ) 

    Open in new window

    or something along those lines?
    using the recordset.delete is normally not the most efficient method ...
    LVL 21

    Expert Comment

    by:Alpesh Patel
    open a new command with the ID in place of rs.Delete

    Author Comment

    Can you explain deeply please..
    LVL 9

    Accepted Solution

    As you are changing the same recordset by deleting itself may be causing this problem. Use
    Instead of rs.Delete use
    Conn.Execute "DELETE FROM applications WHERE FIELD1 = '" & HID & "'"

    Author Closing Comment

    The answer was perfect

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now