private void ReloadTable(TableNamesEnum.TableName tableNames) { switch (tableNames) { case TableNamesEnum.TableName.Provider: providerTableAdapter.Fill(resourcesDataSet.Provider); break; case TableNamesEnum.TableName.Item: itemTableAdapter.Fill(resourcesDataSet.Item); break; } }
/* < General section > * Here are the methods and events that affects * both tables or other things in the interface. */ private int DeleteOperation(TableNamesEnum.TableName tableName, string columnName, string rowId) { //Generate conection string for the Data Base from the 'App.config' file var connectionString = ConfigurationManager.ConnectionStrings[ "Planificador.Properties.Settings.ResourcesDBConnectionString"] .ConnectionString; //Conecting to the SQL database using (var connection = new SqlConnection(connectionString)) { //Body of the insert action var sql = "DELETE FROM " + tableName + " WHERE " + columnName + "= @rName"; connection.Open(); //Association of the conection string and the SQL query var command = new SqlCommand(sql, connection); command.Parameters.AddWithValue("@rName", rowId); //Try to execute the query try { var rowsAffected = command.ExecuteNonQuery(); //The user is informed that the query was made correctly ReloadTable(tableName); return rowsAffected; } catch (SqlException exception) { //The user is informed that there was a problem when executing the query MessageBox.Show(@"Error al eliminar el registro"); throw exception.GetBaseException(); } } }