dotConnect for Snowflake Documentation
Devart.Data.Snowflake Namespace / SnowflakeCommandBuilder Class
Members Example

On this page
    SnowflakeCommandBuilder Class
    On this page
    Automatically generates single-table commands used to reconcile changes made to a System.Data.DataSet with the Snowflake.
    Syntax
    'Declaration
     
    Public Class SnowflakeCommandBuilder 
       Inherits Devart.Data.SqlShimCommandBuilder
       Implements System.ComponentModel.IComponent, System.IDisposable 
    Remarks

    The SnowflakeDataAdapter does not automatically generate the SQL statements required to reconcile changes made to a System.Data.DataSet associated with Snowflake. However, you can create a SnowflakeCommandBuilder object that generates SQL statements for single-table updates. After assigning the SnowflakeDataAdapter to the SnowflakeCommandBuilder, it begins to generate any additional SQL statements that you do not set.

    The relationship between a SnowflakeDataAdapter and its corresponding SnowflakeCommandBuilder is always one-to-one. To create this correspondence, you set the DataAdapter property of the SnowflakeCommandBuilder object. This causes the SnowflakeCommandBuilder to register itself as a listener, which produces the output of SnowflakeDataAdapter.RowUpdating events that affect the System.Data.DataSet.

    To generate INSERT, UPDATE, or DELETE statements, the SnowflakeCommandBuilder uses the SnowflakeDataAdapter.SelectCommand property to retrieve a required set of metadata. If you change the value of SnowflakeDataAdapter.SelectCommand after the metadata has been retrieved (for example, after the first update), you then should call the Devart.Common.DbCommandBuilderBase.RefreshSchema method to update the metadata.

    The SnowflakeCommandBuilder also uses the Connection, CommandTimeout, and System.Data.Common.DbCommand.Transaction properties referenced by the SnowflakeDataAdapter.SelectCommand. The user should call Devart.Common.DbCommandBuilderBase.RefreshSchema if any of these properties are modified, or value of the SnowflakeDataAdapter.SelectCommand property itself is changed. Otherwise the SnowflakeDataAdapter.InsertCommand, SnowflakeDataAdapter.UpdateCommand, and SnowflakeDataAdapter.DeleteCommand properties retain their previous values.

    If you assign null to corresponding property of SnowflakeDataAdapter, the SnowflakeCommandBuilder will be disassociated from the SnowflakeDataAdapter, and the generated commands will no longer be used.

    Note: This class is not available in .NET Standard 1.3 compatible assembly. It is available only in the assembly for full .NET Framework and .NET Standard 2.0 compatible assembly.

    Example
    The following example uses SnowflakeCommand, along with SnowflakeDataAdapter and SnowflakeConnection, to select rows from Snowflake. The example is passed an initialized System.Data.DataSet, a connection string, a query string that is SQL SELECT statement, and a string that is the name of the Snowflake table. The example then creates a SnowflakeCommandBuilder.
    public DataSet SelectSnowflakeSrvRows(string snowflakeConnection,string mySelectQuery,string myTableName)
    {
      SnowflakeConnection myConn = new SnowflakeConnection(snowflakeConnection);
      SnowflakeDataAdapter myDataAdapter = new SnowflakeDataAdapter();
      myDataAdapter.SelectCommand = new SnowflakeCommand(mySelectQuery, myConn);
      SnowflakeCommandBuilder snowflakeCommandBuilder = new SnowflakeCommandBuilder(myDataAdapter);
    
      myConn.Open();
    
      DataSet myDataSet = new DataSet();
      myDataAdapter.Fill(myDataSet, "Departments");
    
      //code to modify data in dataset here
    
      //Without the SnowflakeCommandBuilder this line would fail
      myDataAdapter.Update(myDataSet, "Departments");
    
      myConn.Close();
    
      return myDataSet;
    }
    Public Function SelectSnowflakeSrvRows(snowflakeConnection As String, mySelectQuery As String, myTableName As String) As DataSet
      Dim myConn As New SnowflakeConnection(snowflakeConnection)
      Dim myDataAdapter As New SnowflakeDataAdapter()
      myDataAdapter.SelectCommand = New SnowflakeCommand(mySelectQuery, myConn)
      Dim snowflakeCommandBuilder As SnowflakeCommandBuilder = New SnowflakeCommandBuilder(myDataAdapter)
    
      myConn.Open()
    
      Dim myDataSet As DataSet = New DataSet
      myDataAdapter.Fill(myDataSet, "Departments")
    
      ' Code to modify data in DataSet here
    
      ' Without the SnowflakeCommandBuilder this line would fail.
      myDataAdapter.Update(myDataSet, "Departments")
    
      myConn.Close()
    
      SelectSnowflakeSrvRows = myDataSet
    End Function
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.ComponentModel.Component
             System.Data.Common.DbCommandBuilder
                Devart.Common.DbCommandBuilderBase
                   Devart.Common.DbCommandBuilder
                      Devart.Data.SqlShimCommandBuilder
                         Devart.Data.Snowflake.SnowflakeCommandBuilder

    See Also