Make your own free website on Tripod.com

ADO.NET(SqlDataAdapter);site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/bdadotnetdata3.asp

The preferred way is to specify your own InsertCommand, DeleteCommand, or UpdateCommand completely, because it allows you to explicitly control how the update is done and has better performance than does the auto-generated case.

ADO.NET(SqlDataAdapter);site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/bdadotnetdata3.asp

If you build any table prior to executing the FillDataSet method, the SQLDataAdapter object will simply fill the existing table.

Well this is not totally clear. There are overloads for the fill method where one can specify the table name to be filled, only then we can use the table that we already built.

ADO.NET(SqlDataAdapter);site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/bdadotnetdata3.asp

The preferred way is to specify your own InsertCommand, DeleteCommand, or UpdateCommand completely, because it allows you to explicitly control how the update is done and has better performance than does the auto-generated case.

ADO.NET(SqlDataAdapter);site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/bdadotnetdata3.asp

Using the InsertCommand property

To specify your own INSERT statement, which should be executed when the Update method is called on the DataAdapter object, set the InsertCommand property. The DataAdapter object will execute the specified Insert command to insert the rows in the database. You can use a parameterized Insert query or a stored procedure to set the InsertCommand property.

When using the SQL managed provider, you have to use named parameters in the parameterized query. There is a difference when using parameters with the ADO managed provider, where you use positional parameters with parameter marker as '?'.

You need to set the SourceColumn property for all the parameters. The SourceColumn property tells the DataAdapter object which column in the table is going to provide its value. Set it to the actual parameter name:

Well, it is not obligatory to use the actual parameter name, since we can name parameters and columns differently. The SourceColumn is used to tell the dataadapter where to get values to be used in the update method call, for example when there is a new item in the datatable marked Added then the insert command of the dataadapter is executed and then there is need to get the new values to be inserted and map them to the proper parameters, here comes the role of SourceColumn.

 

And as I was reading on SourceColumn I wondered about how the DataAdapter know which table it should populate, and how to name the tables and columns in a DataSet, so …

 

DataTableMapping, DataColumnMapping; site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconsettingupdatatabledatacolumnmappings.asp

This is the way the DataAdapter maps the database to the dataset. Some points need attention here:

·         First the default DataTableMapping is called “table”

·         We can use that to change the default names and mappings using the name “table”

·         Second we need not specify the DataColumnMapping for all the cols

·         If we don’t the unmapped columns will be named the same as the original ColumnName in the database

·         Third, the kind of mapping can be many to one, meaning many database columns can map to one column in the DataTable. That mapping depends on the order in which the columns appear in the DB, the last column that shares a mapping in the destination DT will have its values in the column of the DT, the previous values of the previous columns will be overridden

·         Fourth, If we specify the DataSet ColumnName to be the same of an un mapped column in the DB then the value in the destination column will follow the previous rule of the order of columns in the DB