Untitled
unknown
csharp
3 years ago
892 B
10
Indexable
// Replace with your connection string string connectionString = "Server=myServer;Database=myDB;User ID=myUsername;Password=myPassword;"; // Create a connection to the database using (SqlConnection connection = new SqlConnection(connectionString)) { // Open the connection connection.Open(); string query = "INSERT INTO myTable (column1, column2, column3) VALUES (@value1, @value2, @value3)"; // Create a command to insert a new record using (SqlCommand command = new SqlCommand(query, connection)) { // Set the command's parameter values command.Parameters.AddWithValue("@value1", "Value 1"); command.Parameters.AddWithValue("@value2", "Value 2"); command.Parameters.AddWithValue("@value3", "Value 3"); // Execute the command command.ExecuteNonQuery(); } } ———————— Contoh cara insert data ke table
Editor is loading...