Information Technology Reference
In-Depth Information
method, so if persistent is needed, this class object must be submitted to
TransactionWrapper objects to realize transaction to guarantee data persistent. If users
get DataTable, they can relize DataTable as data sources which is used to bound to
the Windows visual control,to relize the data automatic updates.
When connecting database, the constructor DataAccessWrapper with four
parameters is direct calede with the user name and password for the database, which
not only connected to the database, and it provided DataTable to operate database
table directly. The class DataAccessWrapper did not provide Save method, so the
class TransactionWrapper had to be used. This will add it to the transaction to realize
the data integrity. Below is the operation implementation on the database CargoTrack:
TransactionWrapper tw = new TransactionWrapper();
DBHelper.DataAccessWrapper
daw
=
new
DataAccessWrapper("sa","","*", "CargoTrack");
daw.Load();
DataTable dt = daw.DataTable;
dt.Rows[0].Delete();
tw.Add(daw);
DBHelper.DataAccessWrapper
daw1
=
new
DataAccessWrapper("sa","", "*","CargoTrack");
daw1.Load();
DataTable dt1 = daw1.DataTable;
DataRow dr = dt1.NewRow();
dr[0] = (Convert.ToInt32(dt1.Rows[dt1.Rows.Count -
1][0])) + 1;
daw1.DataTable.Rows.Add(dr);
tw.Add(daw1);
tw.Save();
Above is two operations performed for table CargoTrack. Execute save method,
and the operation on the database can be kept.
This simple database access architecture makes access to database and modification
to table more easily. Programmers in the design process could cost more time in
business, instead of in thinking access to database and modification to table. This
database access framework is not only used in Cargo_Track system, but in other
systems. If the file app.config is midified in Server address, username, password,
database, use type of database, such as SQL Server Mysql information, it can be used
in other systems to realize the database access.
6 Conclusion
This framework encapsuled over databases operation. Using the technology such as
reflection and control reverse, this custom data access architecture not only achieved
rapid development purpose, but really turned programmers attention from technical to
business. Of course, any one of the proposed framework is not perfect. This simple
data access structure still have some disadvantages, for example, because of bad
encapsulation, it make learning cost taller, performance lower, etc.
Search WWH ::




Custom Search