According to the attached image, I have an attribute class accompanied by the ListarMunicipio
method, where it has a list, in the method then I have public static void InserirOuAtualizar(Municipio municipio)
, I'm working with the nhubernet
functionality, within that method I would like to assign the OracleBulkInsert
, to enter the information in bulk, in another code that I did test using the SqlBulkInsert
and the database Sql Server
I got, but since here in the company we work with layers, I would like to know if it is possible to apply the OracleBulkInsert
function in this method InserirouAtualizar
?
I have this code from the BulkCopy
function below used for SQL
, I wanted to know how I can apply it to the image insertion method without having to pass the connection string until the class already exists for that.
Here is the code I want to apply within the InserirouAtualizar
method 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);
}
}
}
}