Im having problems with my ms acess sql command, well im trying to get the last value from the database

here is my code, the error is ORDER BY clause syntax error..

data.Open()

record.SelectCommand = New OleDbCommand("SELECT PatientID FROM PatientRecord ORDER BY PatientID desc LIMIT 1", data)

Dim ds As New DataSet

Dim dr As DataRow

record.Fill(ds)

dr = ds.Tables(0).Rows(0)

TextBox1.Text = dr(0)

Or is there any alternative to get the last row from the database? Thank you all

Since it is ms access that you are using, you could use

SELECT LAST(columnname) FROM tablename

or

SELECT MAX(columnname) FROM tablename

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.