Study on the use and effect of foreignkeyconstraint foreign KEY constraint [turn]

Source: Internet
Author: User

Original link

da.selectcommand.commandtext="Select Au_id,au_fname,au_lname from authors"; Da. Fill (DS,"Author"); Da.SelectCommand.CommandText="Select au_id,title_id from titleauthor"; Da. Fill (DS,"titleauthor"); Da.SelectCommand.CommandText="Select Title_id,title from titles"; Da. Fill (DS,"Titles"); //Ds. tables["Titles"]. columns["title_id"]. Unique=true; Ds. tables["Titles"]. columns["title_id"]. Allowdbnull=false; Ds. tables["Titles"]. primarykey=NewDatacolumn[]{ds. tables["Titles"]. columns["title_id"]}; //Ds. tables["Author"]. columns["au_id"]. Unique=true; Ds. tables["Author"]. columns["au_id"]. Allowdbnull=false; Ds. tables["Author"]. primarykey=NewDatacolumn[]{ds. tables["Author"]. columns["au_id"]}; //Ds. tables["titleauthor"]. primarykey=NewDatacolumn[]{ds. tables["titleauthor"]. columns["au_id"], ds. tables["titleauthor"]. columns["title_id"]}; //Defining ConstraintsForeignKeyConstraint fk1=NewForeignKeyConstraint ("Authorstitleauthor"Ds. tables["Author"]. columns["au_id"], ds. tables["titleauthor"]. columns["au_id"]); Ds. tables["titleauthor"].    Constraints.add (FK1); ForeignKeyConstraint FK2=NewForeignKeyConstraint ("Titlestitleauthor"Ds. tables["Titles"]. columns["title_id"], ds. tables["titleauthor"]. columns["title_id"]); Ds. tables["titleauthor"].    Constraints.add (FK2);  This. datagrid1.datasource=ds;  This. datagrid1.datamember="titleauthor";

After you set the foreign key, when you edit a record in titleauthor on the DataGrid, the edited record cannot be updated and added when it is not in the title and author.

Study on the use and effect of foreignkeyconstraint foreign KEY constraint [turn]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.