Last post Oct 07, 2010 07:57 AM by riswadkarharshad
Oct 07, 2010 03:35 AM|billylee|LINK
Hi there I'm having a problem trying to get the last record from my database.. I'm doing this:
Dim strSQL As String = "SELECT * FROM tblDatabaseRecords ORDER BY ID DESC LIMIT 1"
Dim myDataAdapter As New OleDbDataAdapter(strSQL, myConnection)
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
Oct 07, 2010 07:42 AM|MetalAsp.Net|LINK
Try like this: SELECT TOP 1 * FROM tblDatabaseRecords ORDER BY ID DESC
Oct 07, 2010 07:57 AM|riswadkarharshad|LINK
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.