Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
SELECT * from table WHERE deadline > datenow
INSERT INTO table (status) VALUES ('closed') WHERE deadline > datenow
Posted
Comments
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.
[no name] 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.

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.
http://msdn.microsoft.com/en-us/library/ms181153(v=sql.105).aspx[^]

Hope it helps...
 
Share this answer
 
Hi
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.
 
Share this answer
 
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.
 
Share this answer
 
Hi
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;
try
{
connection = new SqlConnection(connectionString);
connection.Open();
}
catch
{
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);
adopter.Fill(resultTable);
connection.Close();
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()"
 
Share this answer
 

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