NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

SQLDataSetCommand Class

Represents a set of data commands and a database connection which are used to fill the DataSet and update the data source. At any time, the object refers to only a single record within the current data set.

Object
   Component
      DataSetCommand
         DBDataSetCommand
            SQLDataSetCommand

[Visual Basic]
Public Class SQLDataSetCommand
   Inherits DBDataSetCommand
[C#]
public class SQLDataSetCommand : DBDataSetCommand
[C++]
public __gc class SQLDataSetCommand : public DBDataSetCommand
[JScript]
public class SQLDataSetCommand extends DBDataSetCommand

Remarks

In the past, data processing has been primarily connection-based. Now, in an effort to make multi-tiered applications more efficient, data processing is turning to a message-based approach that revolves around chunks of information. At the center of this approach is the SQLDataSetCommand, which provides a bridge to retrieve and save data between a SQLDataSetCommand and its source data store. The SQLDataSetCommand provides this bridge by mapping FillDataSet, which changes the data in the DataSet to match the data in the data source, and Update, which changes the data in the data source to match the data in the DataSet, requests to the appropriate SQL commands against the data store.

SQLDataSetCommand is used in conjunction with SQLConnection and SQLCommand to increase performance when connecting to a Micrsoft SQL Server database. For all third party SQL server products, as well as other OLEDB-supported databases, it is probably better that you use DataSetCommand along with its associated DBCommand and ADOConnection.

Useful properties include: SelectCommand, InsertCommand, DeleteCommand, UpdateCommand, and TableMappings.

When an instance of SQLDataSetCommand is created, the read/write properties are set to initial values. For a list of these values, see the SQLDataSetCommand constructor.

Requirements

Namespace: System.Data.SQL

Assembly: System.Data.dll

Example [C#]

The following example selects records from an Access data source. The DataSet then uses SQLDataSetCommand, along with SQLCommand and SQLConnection, to insert new records in a SQL Server data source. This example can be modified to migrate an Access database to a SQL Server database.

[C#]

private DataSet InitializeMyDataSet() {
   // creates the table and its columns for the DataSet
   DataSet newData = new DataSet();
   DataTable newTable = newData.Tables.Add("Catagories");

   // add Columns to table
   newTable.Columns.Add("CategoryID",typeof(Int32));
   newTable.Columns.Add("CategoryName", typeof(String));
   newTable.Columns.Add("Description", typeof(String));
   newTable.Columns.Add("Picture",typeof(Byte[]));
   return newData;
}

public void AccessToSQLServer() {
   // set Access connection and select strings
   const string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND_RW.MDB";
   const string strAccessSelect = "SELECT * FROM Categories ORDER BY CategoryID";
   // set SQL Server connection and insert strings
   const string strSQLServerConn = "Data Source=VBsql7;Initial Catalog=Northwind;User ID=sa;Password=;";
   const string strSQLServerInsert = "INSERT INTO Categories(CategoryName, Description, Picture) Values(@CategoryName,@Description,@Picture)";
   // create my DataSet
   DataSet myDataSet = InitializeMyDataSet();
   // create my Access objects
   ADOConnection myAccessConn = new ADOConnection(strAccessConn);
   ADODataSetCommand myAccessDataSetCmd = new ADODataSetCommand();
   myAccessDataSetCmd.SelectCommand = new ADOCommand(strAccessSelect,myAccessConn);
   // create my SQL Server objects
   SQLConnection mySQLConn = new SQLConnection(strSQLServerConn);
   SQLDataSetCommand mySQLDataSetCmd = new SQLDataSetCommand();
   mySQLDataSetCmd.InsertCommand = new SQLCommand(strSQLServerInsert,mySQLConn);
   // fill myDataSet with data from Access
   myAccessConn.Open();
   try {
      myAccessDataSetCmd.FillDataSet(myDataSet,"table");
   }
   finally {
      myAccessConn.Close();
   }

   // update SQL Server with data from the DataSet
   mySQLConn.Open();
   try {
      mySQLDataSetCmd.InsertCommand.Parameters.Add("CategoryName", typeof(String));
      mySQLDataSetCmd.InsertCommand.Parameters.Add("Description", typeof(String));
      mySQLDataSetCmd.InsertCommand.Parameters.Add("Picture", typeof(Byte[]));
      mySQLDataSetCmd.InsertCommand.Parameters[0].SourceColumn = "CategoryName";
      mySQLDataSetCmd.InsertCommand.Parameters[1].SourceColumn = "Description";
      mySQLDataSetCmd.InsertCommand.Parameters[2].SourceColumn = "Picture";
      mySQLDataSetCmd.Update(myDataSet,"table");
   }
   finally {
      mySQLConn.Close();
   }
}

See Also

SQLDataSetCommand Members | System.Data.SQL Namespace | SQLConnection | SQLCommand | DataSet | DataTable