Here is an example of .NET code that writes data to a Snowflake table using the Snowflake.Data library:
using System; using System.Collections.Generic; using System.Data; using Snowflake.Data.Client; namespace SnowflakeWriter { class Program { static void Main(string[] args) { // Define the Snowflake connection string and credentials string connectionString = "account=<your-account>;user=<your-username>;password=<your-password>;db=<your-database>;schema=<your-schema>"; // Define the table name and columns string tableName = "people"; string[] columnNames = { "Name", "Age" }; // Create a list of Person objects to write to the table List<Person> people = new List<Person>() { new Person { Name = "John", Age = 30 }, new Person { Name = "Mary", Age = 25 } }; // Open a connection to Snowflake using (var connection = new SnowflakeDbConnection()) { connection.ConnectionString = connectionString; connection.Open(); // Create a command to insert data into the table using (var command = new SnowflakeDbCommand(connection)) { // Build the SQL insert statement string columns = string.Join(", ", columnNames); string values = string.Join(", ", columnNames); string placeholders = string.Join(", ", columnNames); string sql = $"INSERT INTO {tableName} ({columns}) VALUES ({placeholders})"; // Prepare the command command.CommandText = sql; command.CommandType = CommandType.Text; command.Parameters.Add(new SnowflakeDbParameter("Name", SnowflakeDbType.VARCHAR)); command.Parameters.Add(new SnowflakeDbParameter("Age", SnowflakeDbType.INT)); // Execute the command for each Person in the list foreach (var person in people) { command.Parameters[0].Value = person.Name; command.Parameters[1].Value = person.Age; command.ExecuteNonQuery(); } } // Close the connection connection.Close(); } Console.WriteLine("Data has been written to the Snowflake table."); } } class Person { public string Name { get; set; } public int Age { get; set; } } }
This code defines the Snowflake connection string and credentials, as well as the table name and columns. It creates a list of Person objects to write to the table and uses the SnowflakeDbConnection and SnowflakeDbCommand classes from the Snowflake.Data.Client library to execute an insert statement for each Person in the list. Note that you may need to add a reference to this library in your project before you can use it.