Click here to Skip to main content
15,911,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please,
I want to prevent users from inserting the same record within 24 hours, but however after 24 hours the insertion should be enabled can any one help me please.
I am using asp.net and vb.net.
I have the following fields in my sqldatabase and text boxes on my asp.net form
ClientID, firstName, lastName, DoB
PLEASE HELP ME
Posted
Updated 9-Mar-12 4:35am
v2

To keep them from inserting the same record more than once within 24 hours all you need to do is add an integer field to your primary key and make it the DateTime.DayOfYear[^]. So each day they can only insert one record. I'm not sure if this even makes sense for the kind of table you proposed in your question, but you asked for it and here it is.

Regards,

Manfred
 
Share this answer
 
v2
Comments
Shahin Khorshidnia 23-Mar-12 13:21pm    
My +5
You could add a date to the table and specify a unique index on the specific fields including todays date.
SQL
CREATE TABLE [dbo].[Clients] (
  client_id int ,
  first_name string NOT NULL,
  last_name string NOT NULL
  created_on date NOT NULL
  CONSTRAINT clients_unique UNIQUE ([first_name], [last_name], [created_on])
) ON [PRIMARY]

This way it becomes impossible to add a second client with the same first and last name on a certain date.

Good luck!
 
Share this answer
 
You could add the current day to the list of columns and use collection of columns as the unique identifier.

This probably isn't the best way, but this is what I remember off of the top of my head to get the date in SQL:

SQL
Select Cast(Floor(Cast(getdate() as float)) as datetime)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900