dotConnect for Snowflake Documentation
On this page
    Updating Data
    On this page

    You can update Snowflake data either by modifying the data returned by the SnowflakeDataAdapter class and then calling its Update method, or by executing the corresponding DML statements (INSERT, DELETE, UPDATE, MERGE) via SnowflakeCommand.

    The samples below use the dept table from the schema specified in the Schema connection string parameter. You can create it and fill it with data with the following statements:

    CREATE TABLE dept (deptno INT, dname VARCHAR(14), loc VARCHAR(13));
    INSERT INTO dept VALUES (10, 'ACCOUNTING', 'NEW YORK'), (20, 'RESEARCH', 'DALLAS'), (30, 'SALES', 'CHICAGO'), (40, 'OPERATIONS', 'BOSTON');

    If you use SnowflakeCommandBuilder to generate the INSERT, UPDATE, and DELETE commands for a data adapter, note the following:

    Here is an example showing how to update Snowflake data using SnowflakeDataAdapter.

    using System;
    using System.Data;
    using Devart.Data.Snowflake;
    ...
    class Program
    {
        static void Main(string[] args) {
    
            const string connectionString = "Domain=myorg-myaccount.snowflakecomputing.com;User=your_user;Password=********;Database=your_database;Schema=your_schema;Warehouse=your_warehouse;License Key=**********";
            const string sql = "SELECT deptno, dname, loc FROM dept ORDER BY deptno";
    
            using (SnowflakeConnection connection = new SnowflakeConnection(connectionString)) {
    
                connection.Open();
                DataTable table = new DataTable("Dept");
    
                using (SnowflakeCommand command = connection.CreateCommand()) {
    
                    command.CommandText = sql;
                    using (SnowflakeDataAdapter adapter = new SnowflakeDataAdapter(command)) {
    
                        adapter.Fill(table);
    
                        adapter.UpdateCommand = new SnowflakeCommand("UPDATE dept SET loc = :loc WHERE deptno = :deptno", connection);
    
                        adapter.UpdateCommand.Parameters.Add("deptno", DbType.Int64).SourceColumn = "deptno";
                        adapter.UpdateCommand.Parameters["deptno"].SourceVersion = DataRowVersion.Original;
                        adapter.UpdateCommand.Parameters.Add("loc", DbType.String).SourceColumn = "loc";
    
                        DataRow firstrow = table.Rows[0];
                        firstrow["loc"] = "BOSTON";
                        Console.WriteLine(adapter.Update(table));
                    }
                }
                Console.WriteLine("Rows after update.");
    
                foreach (DataRow row in table.Rows) {
                    Console.WriteLine("{0}\t{1}\t{2}", row[0], row[1], row[2]);
                }
            }
            Console.ReadKey();
        }
    
    }
    
    Imports System
    Imports System.Data
    Imports Devart.Data.Snowflake
    ...
    Module Program
    
        Sub Main()
    
            Const connectionString As String = "Domain=myorg-myaccount.snowflakecomputing.com;User=your_user;Password=********;Database=your_database;Schema=your_schema;Warehouse=your_warehouse;License Key=**********"
            Const sql As String = "SELECT deptno, dname, loc FROM dept ORDER BY deptno"
    
            Using connection As New SnowflakeConnection(connectionString)
    
                connection.Open()
                Dim table As New DataTable("Dept")
    
                Using command As SnowflakeCommand = connection.CreateCommand()
    
                    command.CommandText = sql
                    Using adapter As New SnowflakeDataAdapter(command)
    
                        adapter.Fill(table)
    
                        adapter.UpdateCommand = New SnowflakeCommand("UPDATE dept SET loc = :loc WHERE deptno = :deptno", connection)
    
                        adapter.UpdateCommand.Parameters.Add("deptno", DbType.Int64).SourceColumn = "deptno"
                        adapter.UpdateCommand.Parameters("deptno").SourceVersion = DataRowVersion.Original
                        adapter.UpdateCommand.Parameters.Add("loc", DbType.String).SourceColumn = "loc"
    
                        Dim firstrow As DataRow = table.Rows(0)
                        firstrow("loc") = "BOSTON"
                        Console.WriteLine(adapter.Update(table))
                    End Using
                End Using
                Console.WriteLine("Rows after update.")
    
                For Each row As DataRow In table.Rows
                    Console.WriteLine("{0}" & vbTab & "{1}" & vbTab & "{2}", row(0), row(1), row(2))
                Next
            End Using
            Console.ReadKey()
        End Sub
    
    End Module
    

    The following example updates Snowflake data using SnowflakeCommand.

    using System;
    using Devart.Data.Snowflake;
    ...
    class Program
    {
        static void Main(string[] args) {
    
            const string connectionString = "Domain=myorg-myaccount.snowflakecomputing.com;User=your_user;Password=********;Database=your_database;Schema=your_schema;Warehouse=your_warehouse;License Key=**********";
            const string sql = "UPDATE dept SET loc = 'SEATTLE' WHERE dname = 'SALES'";
    
            using (SnowflakeConnection connection = new SnowflakeConnection(connectionString)) {
    
                connection.Open();
                using (SnowflakeCommand command = connection.CreateCommand()) {
    
                    command.CommandText = sql;
                    Console.WriteLine(command.ExecuteNonQuery());
                }
            }
            Console.ReadKey();
        }
    }
    
    Imports System
    Imports Devart.Data.Snowflake
    ...
    Module Program
    
        Sub Main()
    
            Const connectionString As String = "Domain=myorg-myaccount.snowflakecomputing.com;User=your_user;Password=********;Database=your_database;Schema=your_schema;Warehouse=your_warehouse;License Key=**********"
            Const sql As String = "UPDATE dept SET loc = 'SEATTLE' WHERE dname = 'SALES'"
    
            Using connection As New SnowflakeConnection(connectionString)
    
                connection.Open()
                Using command As SnowflakeCommand = connection.CreateCommand()
    
                    command.CommandText = sql
                    Console.WriteLine(command.ExecuteNonQuery())
                End Using
            End Using
            Console.ReadKey()
        End Sub
    
    End Module
    

    See Also

    Entity Framework Core Support  | Retrieving Data  | Using Parameters