如何将表中的数据复制到同一个表中 [英] How to copy data from a table into the same table
问题描述
嘿伙计们,所以我正在创建一个活动,我想做的是复制去年活动的与会者。
这是我目前的代码:
Hey guys so I am creating an Event and what I want to do is copy over the attendees from last years event.
This is the code I currently have:
protected void Button3_Click(object sender, EventArgs e)
{
string constring = ConfigurationManager.AppSettings["Award_Management2ConnectionString1"].ToString();
SqlConnection con = new SqlConnection(constring);
con.Open();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox check = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("checkAction");
if (check.Checked)
{
string peopleID = GridView1.Rows[i].Cells[4].Text;
string eventID = GridView1.Rows[i].Cells[5].Text;
string DropboxEventID = DropDownList2.SelectedItem.Value.ToString();
string Usercommand = "INSERT INTO People_Event (People_Event.Confirmation,People_Event.People_ID, People_Event.Event_ID) (SELECT People_Event.Confirmation,People_Event.People_ID, '" + DropboxEventID + "' FROM People_Event WHERE (People_Event.People_ID = '" + peopleID + "' AND People_Event.Event_ID = '" + eventID + "')";
SqlCommand command = new SqlCommand(Usercommand, con);
command.ExecuteNonQuery();
}
}
Response.Write("Successfully Copied and Added!!");
con.Close();
GridView1.DataBind();
GridView2.DataBind();
}
然而,这会将人们从一个事件移动(而非复制)到另外,所以当我去观看之前的活动时,参加活动的人不再在那里。
有人可以帮助我吗...我希望能够复制过去几年的与会者,我唯一想要更新的是Even tID等于新的EventID。
这里的任何帮助都将不胜感激。
谢谢
However this moves (not copies) the people from one event to the other, so when I go to view a previous event the people who attended are no longer there.
Can someone please help me here.. I want to be able to copy over attendees from previous years and the only thing I want to update is the EventID to equal to new EventID.
Any help here will be greatly appreciated.
Thank You
推荐答案
Hi,
string Usercommand = "INSERT INTO People_Event (People_Event.Confirmation, People_Event.People_ID, People_Event.Event_ID) VALUES ('no', '" + peopleID + "', '" + DropboxEventID + "')";
此语句不会将人从1个事件移动到另一个事件 - INSERT语句将添加记录,而不是更新现有记录。
您是否直接检查了People_Event表? ...而不是通过前端应用程序查看数据?
This statement does not move people from 1 event to another - an INSERT statement will add records, not update existing records.
Have you checked the People_Event table directly? ... rather than viewing the data via the front end application?
这篇关于如何将表中的数据复制到同一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!