假设有一个表只包含ID, Name, Company
和RealID
。从Asp.NET将行复制到SQL Server中的另一个行
我想复制一行到另一行。对于前:
ID Name Company RealID
1 Marry Company A null
2 Jane Company B null
3 Watson Company C null
4 Marry Company A 1
5 Watson Company C 3
我将通过C#编程语言做到这一点从asp.net。
我的问题是:
在c#下面应该做些什么?
Class: UserProfile {ID, Name, Company, RealID}
代码方面:
UserProfile userProfile = new UserProfile();
//I have userProfile.ID, userProfile.Name, userProfile.Company and userProfile.RealID
SqlConnection conn = new SqlConnection(sqlConnection);
SqlCommand cmd = new SqlCommand("Select * From UserProfile", conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
//and with a loop, assignment to UserProfile members such as UserProfile.ID = dr[0][i]...
和SQL查询后会
INSERT (Name, Company, RealID)
VALUES (UserProfile.Name, UserProfile.Company, UserProfile.RealID)
我搜索这个问题,并发现这一点: Copying values from another row
,但我觉得我的情况下,是不同的。
或者有什么方法可以缩短这个过程吗?
不久:
我想一列从SQL复制asp.net到另一个。
感谢您的帮助
完全以同意。在“插入其他表中的数据”部分中查找[此处](http://technet.microsoft.com/zh-cn/library/dd776381(SQL.105).aspx),示例a。它更简单。 – aikixd 2012-07-31 20:53:34
我认为这个例子非常清楚.. – 2012-08-01 00:25:45