473,941 Members | 7,954 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete range of entries from database!!

7 New Member
Hi All

I am creating a database archiving tool,in which a user can delete all the data before a date he would specify.But the problem is i am not able to create a delete query which can delete a range of data.

I had created the following query
Expand|Select|Wrap|Line Numbers
  1. <% 
  2. pdt=request.form("prevdate")   'contains the date starting from which data has to be deleted
  3. cdt=request.form("currdate")    'contains the date till which data has to be deleted
  4. ' declaring variables
  5. ' not neccesary but a good habit
  6. Dim DataConn
  7. Dim CmdDeleteRecord
  8. Dim MYSQL
  9.  
  10. Set DataConn = Server.CreateObject("ADODB.Connection")
  11.  
  12.  
  13. Set CmdDeleteRecord = Server.CreateObject("ADODB.Recordset")
  14.  
  15. ' The line below shows how to use a system DSN instead of a DNS-LESS connection
  16. ' DataConn.Open "DSN=System_DSN_Name"
  17. DataConn.Open "DBQ=" & Server.Mappath("../fpdb/taxireq.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
  18.  
  19. MYSQL = "DELETE FROM Request_detail WHERE Repdate between '" & pdt &"' and '" & cdt &"'"
  20.  
  21. CmdDeleteRecord.Open MYSQL, DataConn
  22.  
  23. ' closing objects and setting them to nothing
  24. ' not neccesary but a good habit
  25. DataConn.Close
  26. Set DataConn = Nothing
  27. %>
  28.  
please suggest any changes so that i can delete a range of data from the database

Thank You!!
Sep 15 '08 #1
1 1536
omerbutt
638 Contributor
Change Your Current Code with this one
Expand|Select|Wrap|Line Numbers
  1. ' DataConn.Open "DSN=System_DSN_Name"
  2. DataConn.Open "DBQ=" & Server.Mappath("../fpdb/taxireq.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
  3.  
  4. sql_chk="select * from  Request_detail where Repdate between '" & pdt &"' and '" & cdt &"';"
  5. CmdDeleteRecord.open sql_chk,DataConn,3
  6. total_records=CmdDeleteRecord.recordcount
  7. for i=1 to total_records
  8. MYSQL = "DELETE FROM Request_detail WHERE Repdate between '" & pdt &"' and '" & cdt &"'"
  9. CmdDeleteRecord.Open MYSQL, DataConn
  10. loop
  11. DataConn.Close
  12. Set DataConn = Nothing
  13.  
and yes if you do post any questions next time do remember to tell what problem are you having pointing out the exact line in the code
Regards,
Omer Aslam
Sep 15 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
2532
by: Amy G | last post by:
I have received such good help on this message board. I wonder if I might not get a little more help from you on this. I am at the point where I have two dictionaries, with information of a domain and a frequency of that domain. Now that I have the two, I want to delete each entry from one that the two have in common, leaving only those that are unique to the dictionary? Say I have a dictionary called domains_black
4
2761
by: Alistair | last post by:
IIS, Access 2000 I have a page that tabulates data from a DB, this data is items for sale, private ads. is there a way that at the same time it can automatically delete entries that are outside of a specific date..ie. more than a week old?? or should I run two queries seperately..one page which goes through the DB
4
1887
by: Hartmut Jaeger | last post by:
I want to delete a MySQL table without using functions of the OS, so that my php script can run on any webserver. Can I use a command like $sql = "DELETE FROM tablename"; or are there better ways to do the job? Thanks for answers, Hartmut
2
2703
by: dhakate123 | last post by:
Hi Friends.. I want delete repeated entries which comes twice in a table. How to delete that extra entry and keep each single entry using T-SQL statement(SQL server 2000). Please give me the example. Thanks & Regards, Ravi.
1
3427
tolkienarda
by: tolkienarda | last post by:
hi all i have a large database that is matained with a php script. i need to be able to delete every entry in every table with a certain value DELETE FROM (all tables) WHERE (anywhere value appears)='$value' thanks for any help eric
2
2943
by: donno | last post by:
Hi everyone, Im new to php and ive to create a website for uni with the discription below... Design a MySQL database which contains customer information, including name, address, post code, telephone number, email address, type (saler or buyer) and appointment. The web site provides three main functions: (1) Allow the agent to add new customer to the database (2) Allow the agent to search a customer by name (3) Allow the agent to...
6
12849
by: puneetmca | last post by:
I am using Windows XP as my OS and apache server. I have successfully inserted new records into database using forms and now want to delete the records from the database through using radio buttons. Any record i'll select with radio button should be deleted on submit. <? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","root","root");
3
2974
by: lisles | last post by:
hey,i've got a page that displays rows from a db.im want a function to dynamically delete rows.i've put it 1,bt i get an error as follows: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\panchayats\admin\login_attempt.php on line 36 my code is given below: <?php require_once "../inc/functions.php"; sessionCheck(); ?>
3
1856
by: DeteViJete | last post by:
Hello at all, I have a question related to the Delete and Update Query. The folowing table is given: ContractID CarID Count Weight Earnings Explanation: In this table neither ContractID nor the CarID is the primary key. One example:
0
10134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11529
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8218
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.