?
Solved

Visual Basic 6 with SQL

Posted on 2003-02-19
4
Medium Priority
?
206 Views
Last Modified: 2010-04-17
Hi ya, I know I am totally off with this statement but I am trying to delete an entry from a table from my Visual Basic program. I have tried many different things but this is the latest:-

cmd.CommandText = "Select * From Gary Where company = '" & DataInput.c_delete.Text & "'"
cmd.CommandType = adCmdText
MsgBox cmd.CommandText
Set rs = cmd.Execute

If Not rs.EOF Then
    MsgBox "Data Found And Is Being Deleted"
        Do While Not rs.EOF
            cmd.CommandText = "Delete From Gary Where company = '" & DataInput.c_delete.Text & "'"
            cmd.CommandType = adCmdText
            Set rs = cmd.Execute
        Loop
Else
    MsgBox "No Data Found"
End If

As a matter of fact this does delete the field, but has an error message afterwards that causes the program to crash. Id appreciate some help =)

Thanks
0
Comment
Question by:CDeath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Expert Comment

by:yronnen
ID: 7981284
Why working so hard?

Try this:

cmd.CommandText = "DELETE From Gary Where company = '" & DataInput.c_delete.Text & "'"
cmd.CommandType = adCmdText
dim l as long
cmd.execute l
MSGBox l & " Records were deleted"

This will do the same much faster...
0
 

Expert Comment

by:SunnyJoker
ID: 7981424
Like yronnen wrote: You are working to hard. But I think you also have a problem understanding SQL.

The database delets all records that hit the statement : "Delete From Gary Where company = '" & DataInput.c_delete.Text & "'" in one step. You don't have to step through the recordset yourselfe.

Second thing is you have a Do-Loop through 'rs'. When you make the 'Set rs = cmd.Execute' inside the Do-Loop the delete-statement gives nothing back and VB handles you a closed recordset. That's why 'Do While Not rs.Eof' causes an error message.
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 200 total points
ID: 7981636
you need
rs.movenext
before
Loop
0
 

Author Comment

by:CDeath
ID: 8180801
Thanks dude, sorry for the late post, I have been away for a while =)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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