Print Page | Close Window

Adding a Year Range to DB

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=13898
Printed Date: 30 March 2026 at 2:51pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Adding a Year Range to DB
Posted By: Misty
Subject: Adding a Year Range to DB
Date Posted: 19 February 2005 at 3:18pm
I would like to add a year range to a database. The field names are ClassID (primary key) and Year. I don't want to have to add all years to the table. For example, I would like to add all years from 1970 to 2005. How can I add all of the years from 1970 to 2005 to the database without having to manually add them. I want to do this in ASP. Can someone please help me with this?



Replies:
Posted By: dj air
Date Posted: 19 February 2005 at 3:30pm
use a inset query with the value of the year field

something like this

Years Difference = 35

then do a loop and on every loop where you insert a record -1 from the Years Difference.

and set the date value for the database NOW() - year Date difference.

and that way youll add the 35 years gap..

im not sure bit i had problems when trying to insert more than 20 records at once.. might be ok ..


Posted By: Misty
Date Posted: 19 February 2005 at 11:01pm

Here's my code:

 dim FirstYear, LastYear
FirstYear = Request.Form("txtFirstYear") - 1975
LastYear = Request.Form("txtLastYear") - 2005
Dim I
For I = FirstYear to LastYear
If Trim(FirstYear) > "" then
rs.AddNew
rs("Year")= I
rs.Update
End If Next
 
It worked. What do you think about the way I got it to work. Do you think that there will ever be problems with the code that I used?
 


Posted By: dj air
Date Posted: 20 February 2005 at 10:50am
that looks ok

remember to close the connection after the procedure


Posted By: Bluefrog
Date Posted: 20 February 2005 at 5:23pm
Put in some error checking to make sure that you don't end up with some silly amount of loops. ASP doesn't have anything like an Application.DoEvents() method, so it can time out if it is busy for a long time. A small number is fine, but if you get into long procedures with lots of inserts, then you could run into problems. 30 is small, but a few hundred or few thousand could get you in trouble.

-------------
http://renegademinds.com/" rel="nofollow - Renegade Minds - Guitar Software http://renegademinds.com/Default.aspx?tabid=65" rel="nofollow - Slow Down Music



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net