Processing of most tables in. NET multiple languages and Datasets (2)

Source: Internet
Author: User
Tags expression
Data 2 Consider a problem with multiple data tables in a data set

What are the benefits?

It is important that you can easily navigate to get the relevant information, such as province.getcityrows () can get all the cities below the province, And Province.countryrow can get the country where the province is, is it more convenient to check the database than before through the foreign key?

With this kind of navigation comes the convenience of the Cascade update, such as the deletion of the parent record will automatically delete all associated child records, these are automatic, you do not need to write a line of code.

In fact, these are relatively small functions, more powerful function is convenient statistics and aggregation, consider such a demand: for the commodity category table ProductType, I need to calculate the total price of each category of goods and save to the ProductType, we will do before? Now we can write DS like that. Projecttype.totalcolumn. Expression = "Sum (child.price)"; Is it convenient? For example, for school class table class, want to count each class all student grades (fraction) standard deviation and save in the class table Stdev column, then we can write DS. Class.StDevColumn.Expression = "StDev" (child.fraction) is OK.

DataSet Schema: Data set architecture developed in this way it's probably like this.



You can see that this dataset contains almost all the address data, and we can easily navigate through the relationship between the tables.

How do I synchronize with a database?

Unfortunately, the development of the database has yet to catch up, so much so that we have to think about it when we synchronize with the database, and I hope that in the next version of SQL Server, we won't have to be so troublesome.

When retrieving data from a database, we need to instantiate multiple data adapters, each for a single data table, and then populate the corresponding data tables in the dataset with the data they host;

And when the data is updated to the database, we also need to instantiate multiple data adapters, and then update the database table in sequence, in this step, you have to carefully consider the order between them, when the new record, to Piontes table after the child table, delete the first child table.

As shown below:

Public SystemData GetSystemInfo (SqlConnection Sqlcon)

{

SystemData ds = new SystemData ();



SqlDataAdapter dausers = new SqlDataAdapter (Systemsql.strgetusers,sqlcon);

Dausers.fill (ds. Users);



SqlDataAdapter darole = new SqlDataAdapter (Systemsql.strgetrole,sqlcon);

Darole.fill (ds. role);



SqlDataAdapter daruserrole = new SqlDataAdapter (Systemsql.strgetruserrole,sqlcon);

Daruserrole.fill (ds. Ruserrole);



SqlDataAdapter damodule = new SqlDataAdapter (Systemsql.strgetmodule,sqlcon);

Damodule.fill (ds. Module);



SqlDataAdapter damodulefunction = new SqlDataAdapter (Systemsql.strgetmodulefunction,sqlcon);

Damodulefunction.fill (ds. Modulefunction);



SqlDataAdapter darolefunction = new SqlDataAdapter (Systemsql.strgetrolefunction,sqlcon);

Darolefunction.fill (ds. Rolefunction);



SqlDataAdapter dauserfunction = new SqlDataAdapter (Systemsql.strgetuserfunction,sqlcon);

Dauserfunction.fill (ds. Userfunction);



SqlDataAdapter dausercustomparam = new SqlDataAdapter (Systemsql.strgetusercustomparam,sqlcon);

Dausercustomparam.fill (ds. Usercustomparam);



return DS;

}

public void Insupdusers (SystemData ds)

{

datatableextend[] DTS = new DATATABLEEXTEND[4];

Dts[0] = new Datatableextend (ds. Users, "users");

DTS[1] = new Datatableextend (ds. Ruserrole, "Ruserrole");

DTS[2] = new Datatableextend (ds. Usercustomparam, "Usercustomparam");

DTS[3] = new Datatableextend (ds. Userfunction, "userfunction");



Sqlmodify.modifydatabase (Dts,dbname);

}



public void Upddelusers (SystemData ds)

{

datatableextend[] DTS = new DATATABLEEXTEND[4];

Dts[0] = new Datatableextend (ds. Ruserrole, "Ruserrole");

DTS[1] = new Datatableextend (ds. Usercustomparam, "Usercustomparam");

DTS[2] = new Datatableextend (ds. Userfunction, "userfunction");

DTS[3] = new Datatableextend (ds. Users, "users");

Sqlmodify.modifydatabase (Dts,dbname);

}





(To be continued)


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.