[RESOLVED] [2008] Setting Access DB to First Data Row
Hi All,
I am presently converting one of my VB6 programs, which uses an MS Access DB, to VB.Net and as it appears with quite a few others I am having a few conversion problems. Mainly involving the whole dataset, datadaptor scenario.
What I would like to do is ensure that the first row of data is being read so that no records are missed. This was quite simple with VB6 by using the following:
rst.MoveFirst (This may not be required with VB.Net???)
However the code I am using is below.
Code:
Dim conn As OleDbConnection
Dim datAdapt1 As New OleDbDataAdapter()
Dim datTab1 As New DataTable()
With conn
.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source = " & "DB Location"
.Open()
End With
With datAdapt1
.SelectCommand = New OleDbCommand("Select * FROM "A table", conn)
.Fill(datTab1)
End With
"ensure first row of data code entered here"
For Each row In datTab1.Rows
"Do stuff"
Next
The step I am requesting help with may not be required, however I would think there must be some method of assigning a starting row whether it be the first, last or somewhere between
Thanks for any assistance.
Cheers
OZMAN
Re: [2008] Setting Access DB to First Data Row
You don't need anything like that... the For loop will read each record into the row variable (it does effectively the same as .MoveFirst followed by a loop with .MoveNext in it).
Re: [2008] Setting Access DB to First Data Row
With VB6 the .movefirst was required as somewhere it used to keep an index of where the last row was accessed. This meant that prior records were missed if a new call to the data was made. With VB.Net what you are saying is that the FOR EACH procedure will it always start at the first record?
Is there a way to start at another row eg ROW 100 for some reason?
Re: [2008] Setting Access DB to First Data Row
There might be a way to do it, but it doesn't really make much sense (as a database table contains an unordered set of records, rather than an ordered list).
Instead you should be changing your SQL statement to return the records that you want to work with.
Re: [2008] Setting Access DB to First Data Row
What exactly do you want to do with your data once you retrieve it? That will dictate exactly how you access it in the first place.