Home » Asp.netRSS

Select last record from database?!????

Hi there I'm having a problem trying to get the last record from my database.. I'm doing this:

myCommand.Connection.Open()
        Dim strSQL As String = "SELECT * FROM tblDatabaseRecords ORDER BY ID DESC LIMIT 0,1"
        Dim myDataAdapter As New OleDbDataAdapter(strSQL, myConnection)
        myDataAdapter.Fill(myDataTable)
        Form1.DataGridView1.DataSource = myDataTable

myCommand.Connection.Open()
        Dim strSQL As String = "SELECT * FROM tblDatabaseRecords ORDER BY ID DESC LIMIT 1"

        Dim myDataAdapter As New OleDbDataAdapter(strSQL, myConnection)

        myDataAdapter.Fill(myDataTable)

        Form1.DataGridView1.DataSource = myDataTable


but it's saying "Syntax error in ORDER BY clause." Is there something wrong I am doing? Or can I get the last record of my database by another way?


Thanks in advance

 

2 Answers Found

 

Answer 1

Try like this: SELECT TOP 1 * FROM tblDatabaseRecords ORDER BY ID DESC

 

Answer 2

Hi,

Please check if the following query works:

select * from <your_table> where your_id_col = (select max(your_id_col) from your_table)

I hope it helps. 

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter