Tutorials to .com

Tutorials to .com » Dotnet » Database » . net multi-lingual and data set to deal with multiple data tables (2)

. net multi-lingual and data set to deal with multiple data tables (2)

Print View , by: iSee ,Total views: 9 ,Word Count: 828 ,Date: Fri, 12 Jun 2009 Time: 8:46 PM

2, consider a data table there is the problem of multiple data

What are the benefits?

A very important point, it is easy to obtain navigation-related information, such as Province.GetCityRows () access to the province all of the cities below, and can be Province.CountryRow country of this province, is not through foreign keys than before to search the database to facilitate the many subjects?

Along with this is to facilitate the navigation from the cascading updates, such as the deletion of the father of all records will be automatically linked to the deletion of sub-records, which are carried out automatically, you do not need to write single line of code.

In fact, these are relatively small features, more powerful features to facilitate the aggregation of statistics and to consider such a demand: For the commodity type ProductType, I need to calculate each type of commodity prices and save to the sum of Total column the target ProductType , how would we do? Now we can write such a ds.ProjectType.TotalColumn. Expression = "Sum (Child.Price)"; This is not very convenient points? For instance, in the form of classes in schools Class, I hope every statistical achievements of all students in a class (fraction) of the standard deviation and stored in the Class column StDev table, then we can write such a ds.Class.StDevColumn.Expression = "StDev ( Child.fraction "it.

framework data sets: the preparation of the way this development is probably the structure of data sets like this



Can see that the data set contains almost all the address data, the correlation between the adoption of form we can be very convenient in navigation data.

How to sync with the database?

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

Access to data from the database, we need to instantiate multiple data adapters, each adapter for a data table, and then load the data they were filled with data corresponding to the data table;

The database updates the data, we also need to instantiate multiple data adapter, then update the database table, in this step, you should carefully consider the order between them, a new record when the first sub-table after the main table to delete the first sub-table whentable.

As follows:

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)


.Net Database Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.