SQLBulkCopy is not inserting on table

sqlbulkcopy vb.net

Question

I'm using the SQLBulkCopy to load data in my table. It's works fine, but sometimes the data just don't load in my table and I don't receive any errors.

That's my code:

Dim dtbTabelaLoad As New DataTable("base_fat_contrato_linha_composicao")
dtbTabelaLoad.Columns.Add("fk_id_contrato")
dtbTabelaLoad.Columns.Add("access_nbr")
dtbTabelaLoad.Columns.Add("fk_id_composicao")

For Each linha As Linha In objLinhaFinal
    Dim strContrato As String = linha.ComposicaoLinha.NumeroContrato
    Dim strComposicao As String = linha.ComposicaoLinha.NumeroComposicao
    Dim strNumeroLinha As String = linha.NumeroLinha

    dtbTabelaLoad.Rows.Add(strContrato, strNumeroLinha, strComposicao)
Next

Dim load As SqlBulkCopy = New SqlBulkCopy(strStringConexao, SqlBulkCopyOptions.Default)
load.DestinationTableName = "base_fat_contrato_linha_composicao"
load.ColumnMappings.Add("fk_id_contrato", "fk_id_contrato")
load.ColumnMappings.Add("access_nbr", "access_nbr")
load.ColumnMappings.Add("fk_id_composicao", "fk_id_composicao")

load.WriteToServer(dtbTabelaLoad)
load.Close()

I run this code several times in my program, but sometimes the data just doesn't appear on the table.

Accepted Answer

After see the Jacob comment, I discover another process that was erasing the data that was inserted. So, its all ok with my code (happily).

Tks.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow