|
-
Sep 11th, 2008, 08:48 PM
#1
Thread Starter
Hyperactive Member
[2008] Access [SQL] Getting Last Row?
Hi. I'm currently stuck on a part in my application.
vb Code:
SQL = "SELECT CourseID FROM Overview"
Adapter = New OleDbDataAdapter(SQL, Connection)
DS = New DataSet
Adapter.Fill(DS)
If DS.Tables(0).Rows.Count > 0 Then
NewTableName = DS.Tables(0).Rows().Item("CourseID").ToString()
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.
-
Sep 11th, 2008, 09:19 PM
#2
Re: [2008] Access [SQL] Getting Last Row?
-
Sep 11th, 2008, 09:20 PM
#3
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:
Dim table As DataTable = DS.Tables(0) Dim lastRow As DataRow = table.Rows(table.Rows.Count - 1)
-
Sep 12th, 2008, 02:09 PM
#4
Thread Starter
Hyperactive Member
Re: [2008] Access [SQL] Getting Last Row?
vb Code:
Dim table As DataTable = DS.Tables(0)
Dim TableRow As DataRow = table.Rows(table.Rows.Count - 1)
If DS.Tables(0).Rows.Count > 0 Then
NewTableName = DS.Tables(0).Rows(TableRow).Item("CourseID").ToString()
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
-
Sep 12th, 2008, 02:13 PM
#5
Thread Starter
Hyperactive Member
Re: [2008] Access [SQL] Getting Last Row?
Wow I'm stupid, I just looked at my IF statment and used that
vb Code:
Dim TableRow As Integer = DS.Tables(0).Rows.Count - 1 If DS.Tables(0).Rows.Count > 0 Then NewTableName = DS.Tables(0).Rows(TableRow).Item("CourseID") 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|