Click here to Skip to main content
13,150,867 members (46,427 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am trying to make a donation program and i do not know how to close a donation project when a it reaches a deadline.

I want the program to automatically close a project when a deadline is reached. for example if the deadline of a project is january 1 then the status of the project would automatically be closed.

I have a datagridview and I want the column "status" to automatically change from "active" to "closed".

i have an idea on how to do it but i dont really know how to apply it
SELECT * from table WHERE deadline > datenow
INSERT INTO table (status) VALUES ('closed') WHERE deadline > datenow
Posted 31-Dec-12 23:22pm
Zoltán Zörgő 1-Jan-13 5:59am
INSERT INTO table (status) VALUES ('closed') WHERE deadline > datenow is a nonsesne in SQL. I suppose, you will need UPDATE table SET status='closed' WHERE deadline > datenow. But your question is vague, I have the bad feeling, that you have other problems too, some of design kind.
Turbo_23 1-Jan-13 7:12am
Hi, update the status of project using update query. I am not getting what you are exactly trying to do.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In order to achieve the above behavior there are several ways:

1- Create a windows service that kicks a batch program to update the status column in db.
Creating a C# Service Step-by-Step: Lesson I[^]
2- Create SQL Job and set it running every day and it would update the data by end of deadline.[^]

Hope it helps...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


Several ways exists here:

1- Create a SQL Job and execute this every time that you need. you must use T-SQL in your jon for example:

Update [ServerName].[SchemaName].[YourTableName]
Set Status = ''Deactive''
Where Status = ''Active'' And
Date > GETDATE()

2- Create Data-string and execute upper query every time that you need.
3- Create stored-procedure for execute this query

I hope it hels....
If you need more detail please tel me.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

It depends what you mean by 'automatic'. should the text change when the deadline changes, in an open page ? I would suggest that the proc that gets this data, returns a status based on the active date, and additionally could update this data if you wanted it to. There's no need for a separate process, it doesn't matter if your DB is not updated until someone asks for the data.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4


you can create a public class as "DatabaseManagement" and call execute method for run your query. for example:

public class DatabaseManagement
//Create Connection to your Database
public SqlConnection OpenConnection()
string connectionString = "Data Source = YOUR-SERVER-NAME; Initial Catalog = YOUR-DATABASE-NAME; User ID = YOUR-DATABASE-USER-NAME; Password = YOUR-DATABASE-USER-PASSWORD";
SqlConnection connection = null;
connection = new SqlConnection(connectionString);
Console.WriteLine("DataBase is not reachable....");
return connection;

// Execute every query on your Database and return your query result
public DataTable Execute(string queryString)
SqlConnection connection = OpenConnection();
SqlCommand query = new SqlCommand(queryString, connection);
DataTable resultTable = new DataTable();
SqlDataAdapter adopter = new SqlDataAdapter(query);
return resultTable;

After that you can create instance from DatabaseManagement and call Execute method by bellow query:

string query = "Update [ServerName].[SchemaName].[YourTableName] Set Status = ''Deactive'' Where Status = ''Active'' And Date > GETDATE()"

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170924.2 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100