表复制asp.net sql c# [英] table copy asp.net sql c#

查看:67
本文介绍了表复制asp.net sql c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表t1,t2和一个目标表t3



t1有3列

t2有3列(不同栏目)



i插入t1,t2表并成功存储

现在我要复制(列值)所有t1,t2值在t3表中基于(t1.id = t2.id)



如果t1,t2更新意味着t3自动更新这是可能的。

和next我想在gridview中获取所有t3列值

plz help

i have two table t1,t2 and one target table t3

t1 have 3 columns
t2 have 3 columns (different columns)

i inserted t1,t2 tables and stored successfully
now i want to copy(column values) the all t1,t2 values in t3 table based on (t1.id=t2.id )

if t1,t2 updated means t3 automatically update this is possible.
and next i want to fetch all t3 column values in a gridview
plz help

推荐答案





尝试如下。

Hi,

Try like below.
IF NOT EXISTS(SELECT OBJECT_ID('t3'))
BEGIN
    SELECT * INTO t3 from 
    (SELECT A.col1, A.col2, A.col3, A.id, B.t2Col1, B.t2Col2 
    FROM t1 A INNER join t2 B ON A.id = B.id) temp
END

select * from t3





这将创建新表 t3 ,来自 t1 &的列 t2



希望它有所帮助。



This will create new table t3, with the columns from t1 & t2

hope it helps.





我认为你必须从后端做这些事情,



在SqlServer中执行以下代码可能会帮助你...



插入T3

从T1选择T1。*,T2。*

内部加入T1上的T2.Id = T2.Id

其中T1.Id不是空或T2.Id不是空的

和T1.ID不在



选择(姓名,如果T1.Id)从T3



和T2.ID不在



选择(姓名,如果T2.Id)从T3





之后的火灾从T3中选择*并返回结果并绑定到网格。
Hi,

I think you have to do this stuff from Back-End,

execute below code in SqlServer Might helps you...

Insert Into T3
Select T1.*,T2.* from T1
Inner Join T2 on T1.Id = T2.Id
Where T1.Id is not Null or T2.Id is Not Null
And T1.ID Not In
(
Select (Name if T1.Id) From T3
)
And T2.ID not In
(
Select (Name if T2.Id) From T3
)

after that fire "select * from T3" and get result back and Bind to Grid.


这篇关于表复制asp.net sql c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆