Hi,

How to exclude the last record from DatagridView while retrieving data (I am using a SQL Server Database)?

For example, I have 10 records for a particular customer and I want to show only 9 records (excluding the last record). The code below shows all the 10 records belongs to that customer and it needs to be modified.


Code:
Private Sub LoadSearchSalesData()
dgvSales.Columns.Clear()

Try
Dim query As String = "Select CustNo,TrNo,TrDate,Sum(TrAmount) As INVOICE_AMOUNT from SalesTable Where [CustNo] LIKE '" & txtSearchCustNo.Text & "' Group By CustNo,TrNo,TrDate  ORDER BY TrNo DESC"

            Dim adapter As New SqlDataAdapter(query, Connection)
            Dim table As New DataTable()
            adapter.Fill(table)
            dgvSales.DataSource = table

        Catch ex As Exception
            MessageBox.Show($"Error loading Sales Data: {ex.Message}")
     End Try
 End Sub
Please support me with the code.