Hi, I want to copy the data in the PayJour table to the ARCPayJour Table using the Clients Table where the StatusCo = 108. The problem is that the Clients table stop at the first 108 it gets and then do the copy prossecc, but do not go through the rest of the Clients Table to the next 108, and then copy the other data that is equal to 108 in clients table.

Any help please.

Public Function ArchivePayJour()

        con = New SqlConnection(cs)
        cmd = New SqlCommand("SELECT RTRIM(FileNumber), RTRIM(StatusCo) from Clients where StatusCo = '" & "108" & "'", con)
        rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
        With (rdr.Read()) = True
            con = New SqlConnection(cs)
            Dim cb As String = ("INSERT INTO ArcPayJour (CLFileNumber, FullName, SurName, PayDate, ItemCode, RefNumber, Description, Amount, BranchCode, Branch, RecNumber)") &
             "Select RTRIM(CLFileNumber), RTRIM(FullName), RTRIM(SurName), RTRIM(PayDate), RTRIM(ItemCode), RTRIM(RefNumber), RTRIM(Description), RTRIM(Amount), RTRIM(BranchCode), RTRIM(Branch), RTRIM(RecNumber) from PayJour WHERE CLFileNumber=@d1"
            cmd = New SqlCommand(cb)
            cmd.Connection = con
            cmd.Parameters.AddWithValue("@d1", (rdr.GetTextReader(0)))
            For Each row In rdr.Read().ToString
            Next row
        End With

    Catch ex As System.Exception
        MessageBox.Show("Error: Copy " + ex.Message)
    End Try
    Return 0
End Function

Recommended Answers

All 2 Replies

That is because your SELECT statement is only asking to return the FileNumber field value and that is the only value inserted into your table. You need to select all to return all data -

cmd = New SqlCommand("SELECT * from Clients where StatusCo = '" & "108" & "'", con)

If you need to trim some of the returned values, do that after the data is returnd.

AndreRet. Thanks for the help. I haven't keep that in mind. Again, thanks a million..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.