0

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

2
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by Alv45525
0

Change your code to this:

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

0

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.

0

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.

0

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).

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.