Last post Feb 26, 2014 09:12 PM by Terry Guo - MSFT
None
0 Points
4 Posts
Feb 26, 2014 08:51 AM|primagic|LINK
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
Star
12777 Points
1635 Posts
Feb 26, 2014 09:12 PM|Terry Guo - MSFT|LINK
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
None
0 Points
4 Posts
How to skip first two rows in datareader
Feb 26, 2014 08:51 AM|primagic|LINK
I have the following code which reads rows in a datareader
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
Star
12777 Points
1635 Posts
Re: How to skip first two rows in datareader
Feb 26, 2014 09:12 PM|Terry Guo - MSFT|LINK
Hi primagic,
You can set flag variable to avoid the top rows, please try to change your code as below:
Hope it helps.
Best Regards,
Terry Guo