Web应用程序中使用foreach更新表

Web应用程序中使用foreach更新表

本文介绍了如何在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..

推荐答案

INSERT INTO TableName (TaskID, UserID, ReminderDate, Task, TaskType, EmailID)
SELECT  TaskID + 1 AS TaskID, UserID, ReminderDate, Task, TaskType, EmailID
FROM TableName
WHERE ReminderDate = GETDATE()



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更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 07:33