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
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:
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.
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.
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....");
// 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);
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)