using System.Data.SqlClient; // SQL Server connection string string connectionString = "Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;"; // SQL query to insert new row string insertQuery = "INSERT INTO Customers (Name, Address, City, Country) VALUES ('John Smith', '123 Main St', 'Anytown', 'USA')"; // Create SQL connection and command objects using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand(insertQuery, connection)) { // Open connection and execute command connection.Open(); int rowsAffected = command.ExecuteNonQuery(); Console.WriteLine("Rows affected: " + rowsAffected); }
using System.Collections.Generic; using System.Linq; // Create a list of strings ListThis example uses LINQ to add a new item to a list of strings. The Enumerable.Append() method is used to create a new IEnumerablenames = new List { "Alice", "Bob", "Charlie" }; // Add a new name to the list using LINQ names = names.Append("David").ToList(); // Display the updated list foreach (string name in names) { Console.WriteLine(name); }