sql to delete records 
Author Message
 sql to delete records
I would like to add a quick bit of code to my Visual Basic app, to delete
all records from a table where a criteria is met.  For example, I would like
to delete all records from table comments, where custid=123.

Can anyone give me an idea on how to accomplish this in VB ?

Thanks
Tony



Tue, 23 Apr 2002 03:00:00 GMT
 sql to delete records

Quote:

> I would like to add a quick bit of code to my Visual Basic app, to delete
> all records from a table where a criteria is met.  For example, I would like
> to delete all records from table comments, where custid=123.

Access mdb?  Easy to open with DAO, then execute your DELETE SQL:

Dim dbSuperior As Database, strSQL As String
Set dbSuperior = OpenDatabase("C:\SomeFolder\Your.mdb")
strSQL = "DELETE FROM comments WHERE custid = 123"
dbSuperior.Execute strSQL
dbSuperior.Close
Set dbSuperior = Nothing

  Note that punctuation above assumes that field custid is a Number data
type.  If field is Text data type, the value 123 must be surrounded by
single-qoutes:
  ...custid = '123'"
  Hope that helps.
--
Jim in Cleveland
If you're writing to me, in my address
change "REAL_Address.see.below" to "worldnet.att.net"

"What's so funny 'bout peace, love & understanding?"
     - Nick Lowe



Tue, 23 Apr 2002 03:00:00 GMT
 sql to delete records
On Fri, 5 Nov 1999 12:01:29 -0500, "Superior Programming"

Quote:

>For example, I would like
>to delete all records from table comments, where custid=123.

If we're talking DAO, and assuming that CustID is a numeric...

  strSQL = "DELETE FROM Comments WHERE CustID=123;"
  dbCurrent.Execute strSQL, dbFailOnError

  If Err.Number <> 0 Then
  ' etc...

Hope that helps

Tim F

--



Wed, 24 Apr 2002 03:00:00 GMT
 sql to delete records
Sorry for the basic post, but I have been programming in VB for a while, but
haven't had much experience in SQL.

Thanks



Quote:

> > I would like to add a quick bit of code to my Visual Basic app, to
delete
> > all records from a table where a criteria is met.  For example, I would
like
> > to delete all records from table comments, where custid=123.

> Access mdb?  Easy to open with DAO, then execute your DELETE SQL:

> Dim dbSuperior As Database, strSQL As String
> Set dbSuperior = OpenDatabase("C:\SomeFolder\Your.mdb")
> strSQL = "DELETE FROM comments WHERE custid = 123"
> dbSuperior.Execute strSQL
> dbSuperior.Close
> Set dbSuperior = Nothing

>   Note that punctuation above assumes that field custid is a Number data
> type.  If field is Text data type, the value 123 must be surrounded by
> single-qoutes:
>   ...custid = '123'"
>   Hope that helps.
> --
> Jim in Cleveland
> If you're writing to me, in my address
> change "REAL_Address.see.below" to "worldnet.att.net"

> "What's so funny 'bout peace, love & understanding?"
>      - Nick Lowe



Fri, 26 Apr 2002 03:00:00 GMT
 sql to delete records
Excellent.  Thanks for the help


Quote:
> On Fri, 5 Nov 1999 12:01:29 -0500, "Superior Programming"

> >For example, I would like
> >to delete all records from table comments, where custid=123.

> If we're talking DAO, and assuming that CustID is a numeric...

>   strSQL = "DELETE FROM Comments WHERE CustID=123;"
>   dbCurrent.Execute strSQL, dbFailOnError

>   If Err.Number <> 0 Then
>   ' etc...

> Hope that helps

> Tim F

> --




Fri, 26 Apr 2002 03:00:00 GMT
 
 [ 5 post ] 

 Relevant Pages 

1. SQL and deleted records

2. SQL for Deleting records (NEWBIE)

3. Error 3167 Record Deleted when there is no deleted record

4. No records when excluding deleted records in SQL

5. Deleting records from a recordset without deleting from the database

6. Trigger: delete dependent records when deleting a row

7. CRecordset::Delete does not delete my record!

8. Backup: delete old files / Msdb.backupset records delete

9. Deleted records when text file is linked as table (#deleted)

10. DELETE statement (deleting but 0 records affected)

11. Delete a deleted record

12. ado .delete deletes joined table records?


 
Powered by phpBB® Forum Software