1
According to the attached image, I have an attribute class accompanied by the method ListarMunicipio
, where it has a list, in the method below I have public static void InserirOuAtualizar(Municipio municipio)
, I am working with the functionality nhubernet
, within that method I would like to assign the OracleBulkInsert
, to enter the information in bulk, in another code I did test using the SqlBulkInsert
and the database Sql Server
I managed, but since we work with layers here in the company, I wonder if it is possible to apply the function OracleBulkInsert
in that method InserirouAtualizar
?
I own this function code BulkCopy
below used for the SQL
, wanted to know how I can apply it in the method of inserting the image without having the need to pass the connection string up because there is already the class for this.
Follow the code I want to apply within the method InserirouAtualizar
of the image.
private void SqlBulkCopyImport(DataTable dtExcel)
{
using (SqlConnection conn = new SqlConnection()
//@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="" + caminho + "";Extended Properties='Excel 12.0;HDR=No;IMEX=1';"
{
// Abrir conexão.
conn.Open();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn))
{
// Especificando o nome do destino da tabela.
bulkCopy.DestinationTableName = "sdpj_import_processo";
foreach (DataColumn dc in dtExcel.Columns)
{
// Como o numeros das colunas do excel
// não é igual ao numeros de colunas da tabela, precisamos mapear as colunas.
bulkCopy.ColumnMappings.Add(dc.ColumnName, dc.ColumnName);
}
// Escreva o destino do arquivo.
//Define o nome da tabela
//[OPTIONAL]: Mapeie as colunas do Excel com a da tabela do banco de dados
bulkCopy.ColumnMappings.Add("Data de Requisição Pgto", "DAT_REQ_PGTO");
bulkCopy.ColumnMappings.Add("NUMERO PROCESSO ANTERIOR", "NUM_PROC_ANTERIOR");
bulkCopy.ColumnMappings.Add("NUMERO JUDICIAL", "NUM_PROC_JUDICIAL");
bulkCopy.ColumnMappings.Add("COMARCA", "DSC_COMARCA");
bulkCopy.ColumnMappings.Add("VARA", "NUM_VARA");
bulkCopy.ColumnMappings.Add("VARANOME", "NME_VARA");
bulkCopy.ColumnMappings.Add("NOME", "NME_INTERESSADO");
bulkCopy.ColumnMappings.Add("CPF", "CPF_CNPJ_INTERESSADO");
bulkCopy.ColumnMappings.Add("DEENDERECO", "DSC_ENDERECO");
bulkCopy.ColumnMappings.Add("NUENDERECO", "NUM_ENDERECO");
bulkCopy.ColumnMappings.Add("NMMUNICIPIO", "NME_MUNICIPIO");
bulkCopy.ColumnMappings.Add("DECOMPLEMENTO", "DSC_DECOMPLEMENTO");
bulkCopy.ColumnMappings.Add("DEBAIRRO", "NME_BAIRRO");
bulkCopy.ColumnMappings.Add("NUCEP", "NUM_CEP");
bulkCopy.ColumnMappings.Add("NMMUNICIPIO", "NME_MUNICIPIO");
bulkCopy.ColumnMappings.Add("BRUTO", "VLR_BRUTO");
bulkCopy.ColumnMappings.Add("IRPF", "VLR_IR");
bulkCopy.ColumnMappings.Add("LIQUIDO", "VLR_LIQUIDO");
bulkCopy.ColumnMappings.Add("Nº SEP", "COD_SEP");
bulkCopy.ColumnMappings.Add("DATA SEP", "DAT_SEP");
bulkCopy.ColumnMappings.Add("DATA DE RECEBIMENTO NA ORIGEM", "DAT_RECEB_ORIGEM");
bulkCopy.WriteToServer(dtExcel);
}
}
}
}