?
Solved

Visual Basic 6 with SQL

Posted on 2003-02-19
4
Medium Priority
?
215 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
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

609 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