Question Finding the last written record

Roadkyng

New member
Joined
Apr 7, 2010
Messages
3
Programming Experience
1-3
Greetings,

novice here

Access database with a table that has the field RecordID as autonumber.
I need to identify and pass the record number of the highest record in this table, to a text field. This occurs immediately after the record has been written. My code is below. I am getting and IndexOutOfRangeException on the bolded line. Any suggestions would be most appreciated.

Dim strSQL As String = "SELECT MAX([One Time MX OMP tbl].RecordID) FROM [One Time MX OMP tbl]"
Dim cmd2 As New OleDbCommand(strSQL, New OleDbConnection(strConn))
cmd2.Connection.Open()

Dim dataReader As OleDbDataReader = cmd2.ExecuteReader
dataReader.Read()

txtRecordID.Text = dataReader("RecordID").ToString

cmd2.Connection.Close()
cmd2.Connection.Dispose()
 
I guess I should have been more clear as the moderator moved this question. The data tables are based in Access but the code shown above is from an ASP.net / VB.net front end for the website that accesses the data.
 
I guess I should have been more clear as the moderator moved this question.
Contrary to your belief the thread was correctly moved to Database/Access area. This is the VB.Net forum for Access related matters (both winforms and ASP.Net webforms).
Also let me point out, it is not the "txtRecordID.Text" part you have problem with, it is the dataReader("RecordID") part or its prior data access code/query. ;)
 
Contrary to your belief the thread was correctly moved to Database/Access area. This is the VB.Net forum for Access related matters (both winforms and ASP.Net webforms).
Also let me point out, it is not the "txtRecordID.Text" part you have problem with, it is the dataReader("RecordID") part or its prior data access code/query. ;)

I stand corrected. This is my first time to visit and post to this forum.
Could you enlighten me on your second part?
When I change the 'dataReader("RecordID").ToString' to a static value I do not get the error.

It appears the dataread statement is returning an empty string when it should be returning the highest numerical record number
 
Back
Top