Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am making a simple bank application in C# i want to show last five transactions in datagrid view...
wot i have to do.. pls anyone give me some hints...
Posted

1 solution

Since it's a bank transaction, you surely must be saving the datetime value in your database in the table. Use it.
SQL
SELECT 
   TOP 5 myBankTable.transactions 
FROM 
   myBankTable
ORDER BY
   myBankTable.TransactionDate DESC
 
Share this answer
 
Comments
Espen Harlinn 26-Feb-11 9:28am    
Something like that, my 5 :)
codegeekalpha 1-Mar-11 19:52pm    
string query = "select * FROM [transaction] WHERE username='" + txtuser.Text + "'";
ur given query is not working.. i wrote it in comments... correct it if i am wrong.. the qurie which i write above works fine.. but its for alll records... not for recent five transacitons

//string query= " select top 5 from [transaction.transactions ]order by [transaction.transactiondate] desc";
Sandeep Mewara 2-Mar-11 0:15am    
:doh:

I gave you everything and yet you do a mistake even in a copy-paste. I give up.

//string query= " select top 5 from [transaction.transactions ]order by [transaction.transactiondate] desc"
Look at your SQL, it's wrong. Did you even try to run it? Tried to look into error? There is nothing after top 5. You have to mention atleast a column to make it work.

:doh:
codegeekalpha 2-Mar-11 3:23am    
string query = "SELECT TOP 5 depositamount, tdate FROM [transaction] ORDER BY tdate DESC ";

The above query works fine .. but having problem in the fallwing query .. can u pls help me to figure any errror in it
Excetion of a syntax error;;;

string query = "SELECT TOP 5 depositamount, tdate FROM [transaction] ORDER BY tdate DESC where username='"+txtuser.Text+"'";
Sandeep Mewara 2-Mar-11 3:42am    
Do this:

string query = "SELECT TOP 5 depositamount, tdate FROM [transaction] where username='"+txtuser.Text+"' ORDER BY tdate DESC";

ORDER BY should be after WHERE.

I hope now you should get all. Upvote, accept answer and close the question please!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900