如何创建数据集,插入两个数据表并在它们之间建立外键关系. [英] how to Create a dataset, insert two DataTables and establish foriegn key relation between them.

查看:69
本文介绍了如何创建数据集,插入两个数据表并在它们之间建立外键关系.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题不应包含任何数据连接.应将表插入数据集本身.

this question should not have any data connection in it.and the tables should be inserted in the dataset itself.

推荐答案

如何创建数据集:-
How to create dataset:-
DataSet dsCustomer= new DataSet();





1,480,000 results on create dataset in ado.net

Create Two DataTables:-

DataTable customersMast = dsCustomer.Tables.Add("CustomersMaster");
DataTable customersDet = dsCustomer.Tables.Add("CustomersDetails");





1,030,000 results on create datatable in ado.net

Relationship between two datatables:-

ForeignKeyConstraint custOrderFK = new ForeignKeyConstraint("CustOrderFK",
custDS.Tables["CustTable"].Columns["CustomerID"], 
custDS.Tables["OrdersTable"].Columns["CustomerID"]);
custOrderFK.DeleteRule = Rule.None;  
// Cannot delete a customer value that has associated existing orders.
custDS.Tables["OrdersTable"].Constraints.Add(custOrderFK);



如果您有帮助,请不要忘记将其标记为答案.

谢谢



Please don''t forget to mark this as your answer if it helps you out.

Thanks


这篇关于如何创建数据集,插入两个数据表并在它们之间建立外键关系.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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