Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Delete SQL statement with Access 2000 and VB6


Reply
 
Thread Tools Display Modes
  #1  
Old 02-02-2002, 04:42 AM
gogo
Guest
 
Posts: n/a
Unhappy Delete SQL statement with Access 2000 and VB6

Hi,

I built a VB6 application to connect to Access 2000 db. There are 3 fields in the db: id, name and pathname. id is auto-generated.

Here is the del button procedure:

Public x As ADODB.Connection

Private Sub cmddel_Click()
Dim pd As String
pd = "Delete * from tablename WHERE name = '" & txt & "' and path = '" & pathname &"'"
x.Execute pd
End Sub

The code executes alright without error. However, the record in db is NOT deleted.

Any advice?

Thanks

gogo
Reply With Quote
  #2  
Old 02-02-2002, 05:12 AM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

I presume x has been opened before the call?

Why dont you try adding a Debug.Print pd statement just before you exeute it and look in the Immediate/Debug Window to see what the actual command is, because your fields might be a little incorrect. Just now I had the same problem......
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #3  
Old 02-02-2002, 01:02 PM
gogo
Guest
 
Posts: n/a
Default

Sorry, I should state clearly about my question.

I created 4 sets of picture over the VB form, a text input field, a load button and a delete button.

When I enter the id of one of the image categories and click the load button, the set of images will be loaded from Access db according to their path in their local directory.

I created array to store the image id in database.

i.e. array(0) = id1
array(1) = id2
array(2) = id3
array(3) = id4

another set of image:
i.e. array(0) = id5
array(1) = id6
array(2) = id7
array(3) = id8

another set of image:
i.e. array(0) = id9
array(1) = id10
array(2) = id11
array(3) = id12

So, you can see that the id number in the db will be increasing while the image nos. in the form will be remained as array(0 to 3).

I want to select one of them to delete for different sets of images. But, how can I refer to the id of the db? I can choose the array(0 to 3) for one set of images, how to tell the sql to delete the array(3) which equals to id8 in db?

Any advice?

Reply With Quote
  #4  
Old 02-02-2002, 04:14 PM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

I'm a little confused here, but from what I can gather you appear to be wanting this:

Code:
Connection.Execute "DELETE * FROM TableName WHERE ID = '" & id8 & "'"
How is the user choosing id8? Why are id1 to id12 not in an array? Is each set of images a different table?

Sorry, I am completely lost here.....
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #5  
Old 02-02-2002, 08:28 PM
gogo
Guest
 
Posts: n/a
Default

Sorry, I would explain it a little bit.

The form only contains 4 pictures. i.e. each set of image id represents 4 pictures. I used array to store them on the form. But, the id in db is auto-generated and not constrained to only 0-3. It will grow when there are more images to be added.

When the cursor focuses on picture 4, i.e. array(3) in the form. Surely, your SQL statement knows which picture to be deleted. However, when the user selects it over the form, i.e. array(3). As array(3) may represents the id 4, 8, 12, 16, 20 ... pictures in the same table of db.

Hope that more clear.

Regards

gogo

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:

Powered by liquidweb