.NET multi-language and multi-data table processing in the data set (2)

zhaozj2021-02-16  51

2 Consider a problem with multiple data tables in a data set

What is the benefit?

It is important to get relevant information, such as province.getCityRows () can get all cities below this province, and province.countryrow can get the country where the province is located, is it more than before How much is it easy to find to the database?

With this navigation, it is a convenient level update, such as deleting a parent record, automatically all associated sub-records, which are automatically made, you don't need to write a line of code.

In fact, these are relatively small functions, more powerful features are convenient statistics and aggregates, consider such a need: for the product category table ProductType, I need to calculate the price of each class of products and save to the productType target Total column What will we do before? Now we can write ds.projecttype.totalcolumn. Expression = "SUM (child.price)"; Is this very convenient? For example, for the school's class table Class, you want to count all the standards of all students of each class (FRACTION) and saved in the stdev column of the Class table, then we can write ds.class.stdevcolumn.expression = "stdev ( Child.fraction "is OK.

Data Set Architecture: The data set architecture developed by this writing is probably this.

You can see that this dataset contains almost all address data. We can very convenient to navigate in the data set through the association of the intervals.

How to synchronize with the database?

Unfortunately, the development of the database has not yet caught the pace, so that we have to consider a lot when we synchronize with the database, I hope that in the next version of SQL Server, we will no longer need us so trouble.

When obtaining data from the database, we need to instantiate multiple data adapters, each data adapter, and then populate the data in the corresponding data table in the data set, respectively;

When the data update will be updated, we also need to instant multiple data adapters, then update the database of the database, in this step, you have to carefully consider the order between them, when the record is added, After the table, the sub-table will be the primary table after deleting.

As follows:

public

SystemData

GetSystemInfo

(SqlConnection Sqlcon)

{

SystemData DS = new systemdata ();

SqlDataAdapter

Dause

= 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.userCustompaM);

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);

}

(Endlessly)

转载请注明原文地址:https://www.9cbs.com/read-24286.html

New Post(0)