Information Technology Reference
In-Depth Information
As shown in figure of static class, the operation for database is unified in
background. The only programmers should do is to create a DataAccessWrapper
objects, and use Load methed. Because the class DataAccessWrapper didn't have
Save method, if the operate is needed to save, create a TransactionWrapper object is
necessary. The class TransactionWrapperis used to execute transactions, which ensure
the data's integrity and consistency. And the structure can also save with multiple
changes, that is to say, create more than one DataAccessWrapper object, after
changing the table and joining to TransactionWrapper objects, and then execute Save
method , the changes can be saved according to the joined order.
The main DataAccessWrapper implementation code is as follows:
Public Overrides Sub Load()
Me.SelectCommand =DAOWrapper.GetInstance.NewDbCmd
(Me.QueryString, Me.Connection)
Me.Adapter =
DAOWrapper.GetInstance.NewDataAdapter(Me.SelectCommand)
Me.CommandBuilder =
DAOWrapper.GetInstance.NewCmdBuilder(Me.Adapter)
Me.DataTable = fillData(Me.DataSet, Me.Adapter,
Me.TableName) Me.IsLoaded = True End Sub
Private Function fillData(ByRef aDataSet As
DataSet, ByRef adapter As Common.DbDataAdapter, ByVal
tableName As String) As DataTable
Dim rtn As DataTable = Nothing
Try
MyDebugger.Log(Me).Println(Me.SelectCommand.CommandText)
adapter.Fill(aDataSet, tableName.ToLower)
rtn = aDataSet.Tables(tableName.ToLower)
If rtn Is Nothing Then
Throw New NullValueOrRefException("get errors when to
fill Dataset according to the data table") End If
Catch e As Exception
Throw New LoadFailedException(" Fail to create
data according to Datatable query", e)
End Try
Return rtn
End Function
5 Application Conclusion
This Cargo_Track System uses c # language development. In database access, a
database connection statements are written in the config file app.config, while
inversion technology is direct used to connect the database, in the class
DataAccessWrapper. The only programmers could do is according to table to query
string to get DataTable object (subset of database table), in the class
DataAccessWrapper's objects, which is only suitable for single table operation to
return to a subset of the database tables with the primary key. At the same time, this
Subset table (DataTable) can be updated. This class didn't explicit provide Save
Search WWH ::




Custom Search