Click here to Skip to main content
16,011,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi i have table which has columns like TaskID,UserID,ReminderDate,Task,TaskType,EmailID.



Now when the value in ReminderDate column is equal to Today's Date then a new row has to be inserted with the same values.

Here TaskType is Daily,Weekly,Monthly,Yearly,None.

1) ReminderDate value should be replaced with a value based on TaskType value.

2) TaskID is automatically set to incremnet by 1.

pls guide me further..
Posted
Comments
Dholakiya Ankit 23-Jul-13 6:11am    
what u have tried?
Harsha24 23-Jul-13 6:16am    
i was successful in inserting a new row for single record..
But i want to loop it to all the records in the table
santosha epili 23-Jul-13 6:18am    
i suggest, use triggers in database instead of foreach loop

You don't need any loop ;)

Please, test it:
SQL
INSERT INTO TableName (TaskID, UserID, ReminderDate, Task, TaskType, EmailID)
SELECT  TaskID + 1 AS TaskID, UserID, ReminderDate, Task, TaskType, EmailID
FROM TableName
WHERE ReminderDate = GETDATE()
 
Share this answer
 
v2
Hello Harsha,

Agree with santosha,I also suggest to make trigger for it.

Here I mention following post for your better references..

Overview of SQL Server database Triggers[^]

http://technet.microsoft.com/en-us/library/ms189799.aspx[^]

If you getting your solution then please mark this post as answered

Thanks

Renish Ankola
 
Share this answer
 
SqlConnection con = new Sqlconnection("conn");
SqlCommand cmd 
foreach(GridViewRow rw in Gridview1.rows)
{
Textbox txtrmddate  = (Textbox) rw.FindControl("ReminderDate");
Dropdownlist ddltasktyp = (Dropdownlist) rw.FindControl("TaskType");
if (convert.Todatetime(txtrmddate) == Datetime.Now.tostring("dd/MM/yyyy") && ddltasktyp.selectedItem.Text == "Daily"  )
{
con.Open();
cmd = new Sqlcommand("Insert into tblnam (UserID,ReminderDate,Task,TaskType,EmailID) Values (1,'"+ txtrmddate .text  +"','Task','"+ddltasktyp.selectedItem.Text+"','EmailID')",con);


}
}
 
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