locked
How to skip first two rows in datareader RRS feed

  • Question

  • User-922962635 posted

    I have the following code which reads rows in a datareader

     While odr.Read()
                                PrimaryAcctNumber = odr.GetValue(0).ToString
                                CustomerType = odr.GetValue(1).ToString
                                PaymentStatus = odr.GetValue(2).ToString
                                PaymentDate = odr.GetValue(3).ToString
                                PaymentReason = odr.GetValue(4).ToString
                                Source = odr.GetValue(5).ToString
                                PaymentType = odr.GetValue(6).ToString
                                Amount = odr.GetValue(7).ToString
                                CSR = odr.GetValue(8).ToString
                                PaymentID = odr.GetValue(9).ToString
                                AppliedDate = odr.GetValue(10).ToString
                                RejectionDate = odr.GetValue(11).ToString
                                RejectionReason = odr.GetValue(12).ToString
                                Counter = odr.GetValue(13).ToString
                                CustEirMetFlag = odr.GetValue(14).ToString
                                insertdataintosql(PrimaryAcctNumber, CustomerType, PaymentStatus, PaymentDate, PaymentReason, Source, PaymentType, Amount, CSR, PaymentID, AppliedDate, RejectionDate, RejectionReason, Counter, CustEirMetFlag)
                            End While

    How would I skip the first 2 rows of the reader? Its reading an excel spreadsheet and the first to rows of the sheet I don't require

    Wednesday, February 26, 2014 8:51 AM

Answers

  • User697462465 posted

    Hi primagic,

    You can set flag variable to avoid the top rows, please try to change your code as below:

    Dim i As Integer = 0
    While odr.Read()
    	If i < 2 Then
    		i += 1
    		Continue While
    	End If
    	PrimaryAcctNumber = odr.GetValue(0).ToString
    	CustomerType = odr.GetValue(1).ToString
    	PaymentStatus = odr.GetValue(2).ToString
    	PaymentDate = odr.GetValue(3).ToString
    	PaymentReason = odr.GetValue(4).ToString
    	Source = odr.GetValue(5).ToString
    	PaymentType = odr.GetValue(6).ToString
    	Amount = odr.GetValue(7).ToString
    	CSR = odr.GetValue(8).ToString
    	PaymentID = odr.GetValue(9).ToString
    	AppliedDate = odr.GetValue(10).ToString
    	RejectionDate = odr.GetValue(11).ToString
    	RejectionReason = odr.GetValue(12).ToString
    	Counter = odr.GetValue(13).ToString
    	CustEirMetFlag = odr.GetValue(14).ToString
    	insertdataintosql(PrimaryAcctNumber, CustomerType, PaymentStatus, PaymentDate, PaymentReason, Source, _
    		PaymentType, Amount, CSR, PaymentID, AppliedDate, RejectionDate, _
    		RejectionReason, Counter, CustEirMetFlag)
    End While
    

    Hope it helps.

    Best Regards,
    Terry Guo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 26, 2014 9:12 PM