Data Providers
Data Providers are classes that for access to certain types of “data stores”. My guess is that the Database object shown in the above diagram is what the original author calls a “Data Provider”.
The .Net development libraries come “pre-built” with data providers that allow access to SQL Servers, OLE-DB sources, Oracle databases, and ODBC (the one that I have used with Java before). There are also other data providers out there which allow access to MySQL databases and DB2, according to the source’s author.
The different data providersfor the different type of data sources that come with .Net are the following namespaces:
The following is an example of creating and using a Connection object from the System.Data.SQLClient namespace in .Net:
A member of the Connection object, it “acts as the between the database and the disconnected objects” of the ADO .Net object model. This object has a Fill method which fetches the results of as query to the database and stores this in a DataSet or DataTable object. Additionally, this object will submit the “pending changes” that are stored inside of the DataSet object to the database.
What’s weird is the fact that this object also has sub-types (I’m guessing that they’re sub-types) of the Command object, eventhough its owned by the Command object. I guess that it’s not a big deal because the association is aggregation in this model, but it’s just weird to me.
Anyways, the Command properties in the DataAdapter represent the four main SQL queries that are commonly used, that is:
The following Visual Basic code is the definition of function called “CreateCandyAdapter” which has as its parameter an instance of an SqlConnection (subclass of Connection) called “conn”, and its return type (specified by the “As” keyword) is an instance of the SqlDataAdapter (subclass of DataAdapter):
Afterward, the code has the cmd’s value changed to different stored procedure which IS classified as type of UPDATE, I guess, command. The parameters used for the sp_update procedure are specified by lines 18 through 20.
The Parameters field in the SqlDataAdapter class is an instance of the SqlParameterCollection class. The overloaded Add method in the SqlParameterCollection class (in this instance) is used as if it was an SqlParameter constructor. The version of the constructor used in both lines is of the signature (I’m guessing is what it’s called)
“SqlParameter Constructor (String, SqlDbType, Int32, String)”, where parameters map to the fields inside of the SqlParameter class as is shown in the following:
By the way, the SourceVersion of the SqlParameter class is an instance of the DataRowVersion enumerated type which represents the “version” of its DataRow attribute. The DataRow is its own separate class, but I guess that rather than creating an instance of this object you can specify certain information with this enumerated type. I think that each member of this enumerated data type represents the members of the DataRowState enumerated data type, whose members represent the possible values for the RowState property of the DataRow class. The types that this enumeration can take are the following:
An “in-memory cache of data retrieved from a data source”, that consists of DataTable objects that can be “related” to each other with DataRelation objects (MSDN).
(from original source)
The DataTableCollection attribute contains a list of DataTables. Each DataTable object contains the data that was taken from the database and stored in the DataSet object. The hierarchal relationships between the DataTables, are kept in DataRelation objects which are stored in the DataRelationCollection attribute of the DataSet class. Every DataRelation describes a parent-child relationship between any two tables of a database. (MSDN)
DataSet objects read in the data as XML documents. The XML schema and data values for the XML document are transported using HTTP to another application that’s “XML-enabled”. (MSDN) My guess that it’s likely an ASP document since that’s common with .Net.
According to MSDN, the schema obtained by the DataSet object can be written to an XML document (XSD document), using the WriteXmlSchema method. To store the values of this XML document along with the schema, the WriteXml method can be invoked.
The steps (outlined in the MSDN documentation) to create a DataSet object and then to manipulate the data in that object, thus updating the original data), are the following:
Web Service
According to the author of the first source, “the Web Service is the basic unit of work” for software that is developed using the Service Oriented Architecture’s design principles. The Web Service is serves as a middle man between the front-end and back-end components of web-based software. It is created for the sole purpose of returning data to the front-end based on a query.
The following is an example of sending a DataSet as the data that is returned by the Web Service:
Some Visual Basic notes concerning above:
Data Providers are classes that for access to certain types of “data stores”. My guess is that the Database object shown in the above diagram is what the original author calls a “Data Provider”.
The .Net development libraries come “pre-built” with data providers that allow access to SQL Servers, OLE-DB sources, Oracle databases, and ODBC (the one that I have used with Java before). There are also other data providers out there which allow access to MySQL databases and DB2, according to the source’s author.
The different data providersfor the different type of data sources that come with .Net are the following namespaces:
- System.Data.SqlClient
- System.Data.OleDb
- System.Data.OracleClient
- System.Data.Odbc
The following is an example of creating and using a Connection object from the System.Data.SQLClient namespace in .Net:
Code:
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
Dim strConstring As String
Dim intUserID As Integer
strConstring = ConfigurationSettings.AppSettings("constring")
strConstring = "Data Source=(local);Initial Catalog= _Northwind;Integrated Security=SSPI"
sqlConn = New SqlConnection(strConstring)
sqlConn.Open()
DataAdapter
A member of the Connection object, it “acts as the between the database and the disconnected objects” of the ADO .Net object model. This object has a Fill method which fetches the results of as query to the database and stores this in a DataSet or DataTable object. Additionally, this object will submit the “pending changes” that are stored inside of the DataSet object to the database.
What’s weird is the fact that this object also has sub-types (I’m guessing that they’re sub-types) of the Command object, eventhough its owned by the Command object. I guess that it’s not a big deal because the association is aggregation in this model, but it’s just weird to me.
Anyways, the Command properties in the DataAdapter represent the four main SQL queries that are commonly used, that is:
- SelectCommand == SELECT
- UpdateCommand == UPDATE
- InsertCommand == INSERT
- DeleteCommand == DELETE
The following Visual Basic code is the definition of function called “CreateCandyAdapter” which has as its parameter an instance of an SqlConnection (subclass of Connection) called “conn”, and its return type (specified by the “As” keyword) is an instance of the SqlDataAdapter (subclass of DataAdapter):
PHP:
Public Shared Function CreateCandyAdapter(ByVal conn As SqlConnection)_
As SqlDataAdapter
Dim da As SqlDataAdapter = New SqlDataAdapter
Dim cmd As SqlCommand
Dim parm As SqlParameter
' Create the SelectCommand.
cmd = New SqlCommand("sp_select", conn)
cmd.CommandType = CommandType.StoredProcedure
da.SelectCommand = cmd
' Create the UpdateCommand
cmd = New SqlCommand("sp_update", conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@CandyName", SqlDbType.VarChar, 5, "CandyName")
cmd.Parameters.Add("@CandyDescription", SqlDbType.VarChar, 40, _
"CandyPrice")
parm.SourceVersion = DataRowVersion.Original
da.UpdateCommand = cmd
Return da
End Function
Note: “Shared” attributes and operations are members of a class in Visual Basic. They can be invoked by either using an instance of the class or by calling on the class-name itself (like what you do with “static” methods in Java or C#) (MSDN).
In line 9, the cmd variable is set to equal a new instance of an SQLCommand whose command is a stored-procedure named “sp_select”, and that the database that this command is assigned to is the one specified by the conn SqlConnection object. The line that follows after allows the cmd object to know that the its command is a stored-procedure.
Afterward, the code has the cmd’s value changed to different stored procedure which IS classified as type of UPDATE, I guess, command. The parameters used for the sp_update procedure are specified by lines 18 through 20.
The Parameters field in the SqlDataAdapter class is an instance of the SqlParameterCollection class. The overloaded Add method in the SqlParameterCollection class (in this instance) is used as if it was an SqlParameter constructor. The version of the constructor used in both lines is of the signature (I’m guessing is what it’s called)
“SqlParameter Constructor (String, SqlDbType, Int32, String)”, where parameters map to the fields inside of the SqlParameter class as is shown in the following:
- String: ParameterName – specifies the name of the parameter seen inside the sql c0mmand.
- SqlDbtype: The field of the same name as this data type. This is important because certain data types are different from database to database
- Int32 (or int): Size – specifies the max number of bytes that the specified field is allowed to have.
- String: SourceColumn – specifies the “column” inside of the DataSet that this SqlCommand maps to (according to one page at the MSDN website). But, the DataSet class doesn’t have a list of “columns”. However, the DataTable class does have an attribute called Columns. I think that this is what the writer of that page meant.
By the way, the SourceVersion of the SqlParameter class is an instance of the DataRowVersion enumerated type which represents the “version” of its DataRow attribute. The DataRow is its own separate class, but I guess that rather than creating an instance of this object you can specify certain information with this enumerated type. I think that each member of this enumerated data type represents the members of the DataRowState enumerated data type, whose members represent the possible values for the RowState property of the DataRow class. The types that this enumeration can take are the following:
- Default: The value that’s found in the default value for the DataRowState enumeration. This value would be equivalent to one of the other values for DataRowVersion instances.
- Current: DataRowState is either Added, Modified, or Current.
- Original: DataRowState is Deleted.
- Proposed: DataRowState is Detached.
An “in-memory cache of data retrieved from a data source”, that consists of DataTable objects that can be “related” to each other with DataRelation objects (MSDN).

The DataTableCollection attribute contains a list of DataTables. Each DataTable object contains the data that was taken from the database and stored in the DataSet object. The hierarchal relationships between the DataTables, are kept in DataRelation objects which are stored in the DataRelationCollection attribute of the DataSet class. Every DataRelation describes a parent-child relationship between any two tables of a database. (MSDN)
DataSet objects read in the data as XML documents. The XML schema and data values for the XML document are transported using HTTP to another application that’s “XML-enabled”. (MSDN) My guess that it’s likely an ASP document since that’s common with .Net.
According to MSDN, the schema obtained by the DataSet object can be written to an XML document (XSD document), using the WriteXmlSchema method. To store the values of this XML document along with the schema, the WriteXml method can be invoked.
The steps (outlined in the MSDN documentation) to create a DataSet object and then to manipulate the data in that object, thus updating the original data), are the following:
- Using a DataAdapter to specify the original source of the data (not necessarily a database, I gather), the DataTable objects are created and filled.
- Update, delete, or insert new data to the data that’s stored in each DataTable object. The original documentation doesn’t specify how, but I guess that the use of Command objects would be one way of doing this.
- Use the DataSet.GetChanges method to get another DataSet object that contains only the changes that were made to this DataSet.
- Invoke the DataAdapter.Update method, and specify the DataSet obtained in step 3 as its argument.
- Merge changes made in the second DataSet with the first DataSet by invoking the Merge method of this DataSet class and specify the second DataSet as its parameter.
- Either accept or cancel changes by invoking the AcceptChanges and RejectChanges methods of the DataSet class respectively.
PHP:
Private Shared Sub DemonstrateGetXml()
' Create a DataSet with 1 table two columns and 10 rows.
Dim ds As DataSet = New DataSet("myDataSet")
Dim t As DataTable = ds.Tables.Add("Items")
t.Columns.Add("id", Type.GetType("System.Int32"))
t.Columns.Add("Item", Type.GetType("System.String"))
' Add ten rows.
Dim r As DataRow
Dim i As Integer
For i = 0 To 9
r = t.NewRow()
r("id") = i
r("Item")= "Item" & i
t.Rows.Add(r)
Next
' Display the DataSet contents as XML.
Console.WriteLine( ds.GetXml() )
End Sub
According to the author of the first source, “the Web Service is the basic unit of work” for software that is developed using the Service Oriented Architecture’s design principles. The Web Service is serves as a middle man between the front-end and back-end components of web-based software. It is created for the sole purpose of returning data to the front-end based on a query.
The following is an example of sending a DataSet as the data that is returned by the Web Service:
PHP:
<WebMethod()> Public Function GetRequests(ByVal RequestedStatus As
Boolean) As DataSet
'db connection
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
Dim strConstring As String
Dim intUserID As Integer
strConstring = ConfigurationSettings.AppSettings("constring")
sqlConn = New SqlConnection(strConstring)
sqlConn.Open()
sqlCmd = New SqlCommand
With sqlCmd
.Connection = sqlConn
.CommandTimeout = 30
.CommandType = CommandType.StoredProcedure
If RequestedStatus = True Then
.CommandText = "spGetOpenRequests"
Else
.CommandText = "spGetClosedRequests"
End If
End With
Dim RequestDA As SqlDataAdapter = New SqlDataAdapter
RequestDA.SelectCommand = sqlCmd
Dim RequestDS As DataSet = New DataSet
RequestDA.Fill(RequestDS, "RequestType")
Return RequestDS
sqlConn.Close()
End Function
- The ByVal keyword is used to specify that the parameter is “passed by value” – meaning that it cannot change the value of the variable in the calling function from which it is from.
- The With keyword is something strange to me, because I don’t think that I’ve ever seen it before. This keyword is used to specify a series of statements that all refer to the same variable. In line 14, the sqlCmd is used as the reference of the With block. Pay notice to how the sqlCmd object isn’t mentioned before each of the “.<attribute>“ statements. From what I see, it looks like a With-block is much like a temporary function inside of a referenced class, but I don’t think that the referenced variable has to necessarily be an instance of a class but probably could be a primitive data-type. Although, I don’t see how primitive data types would benefit from these kinds of block statements.