Results 1 to 4 of 4

Thread: [2005] SqlBulkCopy ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    175

    Question [2005] SqlBulkCopy ?

    Hi guys! all ok?
    what i need to know is how to do a SqlBulkCopy if the 2 tables arent identical!
    or if there is a easy/best way to do it!
    ill try to explain with an example:

    table 1 : Id(int)-Pk ; REF(nchar(10)) ; Description(Nvarchar(max))

    Table 2 : Id(int)-pk ; ClientId(int) ; Description(Nvarchar(max))

    i want to do a SqlBulkCopy from table 1 only for the descripion field
    and ClientId is the current client (from a Label)
    How can i do This?
    anny ideas?
    Last edited by Motorui; Apr 5th, 2007 at 04:57 AM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    175

    Re: [2005] SqlBulkCopy ?

    I want to do this in a button click event!
    please help!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    175

    Re: [2005] SqlBulkCopy ?

    Please tell me if i´m in the correct way!?

    Code:
            Dim cnGHA As New SqlConnection(My.Settings.dbContractosConnectionString)
            Dim strDescricao As String = "SELECT Id, Descricao FROM dbo.GHA"
            Dim cmdDescricao As New SqlCommand(strDescricao, cnGHA)
            Dim strAtribuiGHA As String = "INSERT INTO dbo.AtribuiGHA(CompanhiaId, Descricao) VALUES (@CompanhiaId,@Descricao)"
            Dim cmdAtribuiGHA As New SqlCommand(strAtribuiGHA, cnGHA)
    
    
            Try
                cnGHA.Open()
                Dim sdrGha As SqlDataReader = cmdDescricao.ExecuteReader
                With sdrGha
                    If .HasRows Then
    
                        While .Read
    
                        End While
    
                    End If
                    .Close()
                End With
            Finally
                cnGHA.Close()
            End Try

    if not what am i missing??

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    175

    Re: [2005] SqlBulkCopy ?

    Code:
       Dim cnSQL As SqlConnection
            Dim cmSQL As SqlCommand
            Dim drSQL As SqlDataReader
            Dim strSQL As String
            Dim strSQL2 As String
            Dim cmSQL2 As SqlCommand
    
            Try
                ' Cria a instrução SELECT para consultar informação
                strSQL2 = "INSERT INTO [AtribuiGHA] ([REF], [CompanhiaId], [Descricao]) VALUES (@REF, @CompanhiaId, @Descricao);"
                strSQL = "SELECT Descricao, REF FROM GHA"
                cnSQL = New SqlConnection(My.Settings.ConContractos)
                cnSQL.Open()
                cmSQL2 = New SqlCommand(strSQL2, cnSQL)
                cmSQL = New SqlCommand(strSQL, cnSQL)
                drSQL = cmSQL.ExecuteReader
                If drSQL.Read Then
                    Do While (drSQL.Read)
                        cmSQL2.Parameters.Add("@REF" = drSQL("REF").ToString)
                        cmSQL2.Parameters.Add("@CompanhiaId" = Me.CompanhiaIDDadosGeraisTextBox.Text)
                        cmSQL2.Parameters.Add("@Descricao" = drSQL("Descricao").ToString)
                        cmSQL2.ExecuteNonQuery()
                        drSQL.NextResult()
                    Loop
                End If
    
                ' fecha e limpa objetos
                drSQL.Close()
                cnSQL.Close()
                cmSQL.Dispose()
                cnSQL.Dispose()
    
            Catch ex As SqlException
                MsgBox(ex.Message, MsgBoxStyle.Critical, "Erro SQL")
    
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Critical, "Erro Geral")
            End Try
    What is wrong in this???

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width