如何在asp.net Web应用程序中使用foreach更新表 [英] how to use foreach in updating a table in asp.net web application
本文介绍了如何在asp.net Web应用程序中使用foreach更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表格中包含TaskID,UserID,ReminderDate,Task,TaskType,EmailID等列。
现在当ReminderDate列中的值等于今天的日期时,必须插入一个具有相同值的新行。
这里TaskType是每日,每周,每月,每年,无。
1)ReminderDate值应替换为基于TaskType值的值。
2)TaskID自动设置为增量为1.
请指导我..
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..
推荐答案
你不需要任何循环;)
请测试一下:
You don't need any loop ;)
Please, test it:
INSERT INTO TableName (TaskID, UserID, ReminderDate, Task, TaskType, EmailID)
SELECT TaskID + 1 AS TaskID, UserID, ReminderDate, Task, TaskType, EmailID
FROM TableName
WHERE ReminderDate = GETDATE()
Hello Harsha,
同意santosha,我也建议触发它。
这里我提到以下帖子以便您更好地参考..
SQL Server数据库触发器概述 [ ^ ]
http://technet.microsoft.com/en-us/library/ms189799.aspx [ ^ ]
如果你得到了解决方案,那么请标记发表回复
谢谢
Renish Ankola
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
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);
}
}
这篇关于如何在asp.net Web应用程序中使用foreach更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文