Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

oledbReader does not show all the records..Probably Missing first one.

Status
Not open for further replies.

TekMem

Programmer
Joined
Jul 23, 2004
Messages
98
Location
CA
The following codes give me 125 records while same select statement using count (*) gives 126.

I have spent a lot of time but could not figure out.
need help.


Sub test1()
Dim strconnection As String
'Dim class1 As New clsDbConnection
Dim _dbname As String
Dim sr As StreamReader = New StreamReader("db_alias_nm.txt")
Dim con As OleDbConnection
_dbname = sr.ReadToEnd
Console.WriteLine(_dbname)
sr.Close()

strConnection = "Provider=MSDAORA.1;User ID=pwmgr;Data Source=" & ds & ";Password=" & pw
con = New OleDbConnection(strconnection)
'class1.strConnection()
Dim testq As String
testq = " select * from " _
& " IOTRANSFERS " _
& " where ((varchar_255_40 =1 and varchar_255_70 is null)" _
& " or(varchar_255_41 =1 and varchar_255_71 is null))" _
ORDER BY VARCHAR_255_32"
Dim c As OleDbCommand

Dim testreader As OleDbDataReader
c = New OleDbCommand(testq, con)
con.Open()
' On Error GoTo ErrorHandle
testreader = c.ExecuteReader()
testreader.Read()
Dim tt As Integer
Do While testreader.Read

tt += 1
Debug.WriteLine(tt & testreader("varchar_255_17"))
Loop
testreader.Close()
con.Close()
End Sub
 
It is because your loop is a 0-index loop (it starts at zero).

If you number 126 items starting at 0 (0,1,2,3,4...123,124,125) the last number will be 125 even though there are 126 items.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks Rick,

Do While testreader.Read

tt += 1
Debug.WriteLine(tt & testreader("varchar_255_17"))

Loop
The values are starting from (1,2.........125)and the vary first value from ("varchar_255_17") is missing too.

How should I change my code so that the first value appears.
Similar kind of loops I have used before and results were O.k.

 
Code:
testreader.Read()
You are doing this before your loop...



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top