473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Delete range of entries from database!!

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 1513
omerbutt
638 512MB
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
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...
4
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...
4
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...
2
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...
1
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...
2
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,...
6
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....
3
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.