hello guys, i really need help....i have a transaction table in ms access N i want to retrieve last 10 transaction from the table from my vb form...how am i suppose to do it???i used the folloing code but it is displaying all transactions of a specific account number. N i just need the last ten. Plz gimme some ideas.


Private Sub btnClick_Transactions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClick_Transactions.Click
Dim BalConn As OleDb.OleDbConnection
Dim dsBal As DataSet

BalConn = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Database\VB.net.mdb")
Dim strSQL As String
dsBal = New DataSet

strSQL = "select * from tbl_Transactions where Account_Number='" & UserAccGlobal_Login & "'"

Try

BalConn.Open()
Dim daMyAdapter = New OleDb.OleDbDataAdapter(strSQL, BalConn)
daMyAdapter.Fill(dsBal, "Account_Number")

datTransactions_Grid.DataSource = dsBal
datTransactions_Grid.DataMember = "Account_Number"

Catch ex As Exception

MessageBox.Show(ex.Message, "Exception Raised")

Finally
BalConn.Close()

End Try
End Sub


Private Sub frmTransactions_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

ClosingTransaction.Enabled = True

End Sub

Change your code to this:

strSQL = "select top 10 from tbl_Transactions where Account_Number='" & UserAccGlobal_Login & "'"

thx for rply but it does not work:
it says:
the SELECT statement includes a reserved word or argument name that is misspelled or missing, or punctuation is incorrect.

Hello,

Sorry it should be "SELECT TOP 10 *"

Give that a shot.

Jenni

it works but the problem is that i need the last ten records added. And the code above selects the top 10 from my table.

If you need the last ten records updated you'll have to sort by some column; ideally a DateTime field. If there is a primary key field you can use that too. For example if u had a column called "DateAdded" just add this:

"SELECT * FROM TABLE
ORDER BY DateAdded DESC"

The DESC is descending order. If that is the opposite of what you need then use ASC (ascending).

I tried something like
"SELECT TOP 10* FROM Table ORDER BY DateAdded DESC.......but is
not working either.

Hey thx a lot for yur help...i got the solution.
ThanX

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.