与父表有关系时,如何在子表中插入记录. [英] How to insert a record into a child table when there is relation with parent table.

查看:184
本文介绍了与父表有关系时,如何在子表中插入记录.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拿了2张桌子-> 1)Dayprogram1
2)TimeAllocate

我已经把他们两个都联系起来了

I have taken 2 tables -> 1)Dayprogram1
2)TimeAllocate

and i have taken relation both of them like

con = new SqlConnection("Initial Catalog=customer;data source=arun;Integrated Security=SSPI");
            da = new SqlDataAdapter("Select * from dayprogram1", con);
            da1 = new SqlDataAdapter("Select * from TimeAllocate where code=100", con);
            ds = new DataSet();
            da.Fill(ds, "dayprogram1");
            da1.Fill(ds,"TimeAllocate");
            dr = new DataRelation("parent", ds.Tables["dayprogram1"].Columns["code"], ds.Tables["TimeAllocate"].Columns["code"]);
            ds.Relations.Add(dr);
            dr.ChildKeyConstraint.DeleteRule = Rule.None;
            dr.ChildKeyConstraint.UpdateRule = Rule.None;
            loaddata();


现在我想在TimeAllocate Table中输入一条记录...我没有一个主意...任何人都可以帮助我


Now i want to enter a record into TimeAllocate Table...I am not getting an idea...any one help me

推荐答案

首先在子表中输入数据,获取主键,并使用该主键将数据插入父表.
First enter data in child table, get the Primary key and insert data into parent table with that primary key.


这篇关于与父表有关系时,如何在子表中插入记录.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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