MySqlCommand command = new MySqlCommand("SELECT * FROM employees", connection);
MySqlCommand command = new MySqlCommand("INSERT INTO employees (name, age) VALUES (@name, @age)", connection); command.Parameters.AddWithValue("@name", "John Doe"); command.Parameters.AddWithValue("@age", 35); int numRowsAffected = command.ExecuteNonQuery();
MySqlCommand command = new MySqlCommand("AddEmployee", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@name", "John Doe"); command.Parameters.AddWithValue("@age", 35); int numRowsAffected = command.ExecuteNonQuery();In this example, we create a MySqlCommand object to execute a stored procedure named AddEmployee that adds a new employee with name and age values. We set the CommandType property to CommandType.StoredProcedure and add parameters to the command. We then execute the command and retrieve the number of rows affected. The package library used in these examples is the MySql.Data package, which is available on NuGet.