Results 1 to 5 of 5

Thread: [2008] Access [SQL] Getting Last Row?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    [2008] Access [SQL] Getting Last Row?

    Hi. I'm currently stuck on a part in my application.

    vb Code:
    1. SQL = "SELECT CourseID FROM Overview"
    2.             Adapter = New OleDbDataAdapter(SQL, Connection)
    3.             DS = New DataSet
    4.             Adapter.Fill(DS)
    5.             If DS.Tables(0).Rows.Count > 0 Then
    6.                 NewTableName = DS.Tables(0).Rows().Item("CourseID").ToString()
    7.             End If

    What I'm trying to do. is when the Application Loads, I need it to get the Last INDEX in the CourseID Form and I guess add 1 to it. I forget how do it, but I believe its something to do with Reader and a Integer I guess. Like While Reader = True then Count + 1.


    How would I go about doing this? Its something in here

    NewTableName = DS.Tables(0).Rows(!HERE!).Item("CourseID").ToString()

    That I'm going need a variable or something.

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2008] Access [SQL] Getting Last Row?


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

    Re: [2008] Access [SQL] Getting Last Row?

    If you're saying that you need to get the last row then, like every collection, it's at index (Count - 1).
    vb.net Code:
    1. Dim table As DataTable = DS.Tables(0)
    2. Dim lastRow As DataRow = table.Rows(table.Rows.Count - 1)
    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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    Re: [2008] Access [SQL] Getting Last Row?

    vb Code:
    1. Dim table As DataTable = DS.Tables(0)
    2.             Dim TableRow As DataRow = table.Rows(table.Rows.Count - 1)
    3.             If DS.Tables(0).Rows.Count > 0 Then
    4.                 NewTableName = DS.Tables(0).Rows(TableRow).Item("CourseID").ToString()
    5.             End If


    Can't Convert Integer into DataRow

    How do I make TableRow a Integer while keeping the table.Rows(table.Rows.Count -1) ? I'm trying to get the last index then set it to add to that on a NEW TABLE

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    Re: [2008] Access [SQL] Getting Last Row?

    Wow I'm stupid, I just looked at my IF statment and used that

    vb Code:
    1. Dim TableRow As Integer = DS.Tables(0).Rows.Count - 1
    2.             If DS.Tables(0).Rows.Count > 0 Then
    3.                 NewTableName = DS.Tables(0).Rows(TableRow).Item("CourseID")
    4.             End If

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