Results 1 to 5 of 5

Thread: [RESOLVED] [2008] Setting Access DB to First Data Row

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    25

    Resolved [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

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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).

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    25

    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?

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width