Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends ,


here i inserted the multiple rows in msaccess table, so i need to retrive the last rows of column details , please help me out .


here i done with this code

which im retriving the last logindetails.

in my table :

col 1= ID,
col 2= username,
col 3=login,
col 4=logut.


here is should get the login and logout ,last column details with the help of username.

cmdd = new OleDbCommand("select  * from logindetails where [lusername]='" + loginusername + "'", conn);
           conn.Open();
           cmdd.ExecuteNonQuery();
           OleDbDataAdapter da = new OleDbDataAdapter(cmdd);
           da.Fill(dt);

           lbllogin.Content=dt.Rows[0]["login"].ToString();
           lbllogout.Content = dt.Rows[0]["logout"].ToString();


please help me out.

thank u in advance.
Posted
Comments
Charlemagne Gustilo 14-Mar-14 6:34am    
Do you have an identity column? If so, you can simply get the last row by selecting MAX(FieldName).
Raajkumar.b 15-Mar-14 2:43am    
int i=dt.rows.count;
lbllogin.Content=dt.Rows[i-1]["login"].ToString();
lbllogout.Content = dt.Rows[i-1]["logout"].ToString();

Hi,

This is a basic idea please work on it.

SQL
select top(1)  *,max(login) as LastLogintime from logindetails where [lusername]='" + loginusername + "'" 
 
Share this answer
 
Comments
Mr.VJ 14-Mar-14 7:41am    
thank u ,

i tried ,but getting

EXCEPTION :

The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
select top(1)  *   from logindetails where [lusername]='" + loginusername + "'"  order by ID desc

N.B.where ID is your PK. Select last record as top 1 with descending order
 
Share this answer
 
v3
Comments
Mr.VJ 14-Mar-14 7:41am    
thank u ,

i tried ,but getting

EXCEPTION :

The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
[no name] 14-Mar-14 7:50am    
See again this query I have updated it. You will get detail info from * findings
thank you friends , for suggesting me ..


i solved my self

i retrived last second row by taking count-2;



here is the code :

cmdd = new OleDbCommand("select * from logindetails where [lusername]='" + loginusername + "'", conn);
            conn.Open();
            cmdd.ExecuteNonQuery();
            OleDbDataAdapter da = new OleDbDataAdapter(cmdd);
            da.Fill(dt);
            da.Fill(ds);
            int i;
            
                for ( i = 0; i <= dt.Rows.Count-2;i++ )
                {
                    lbllogin.Content = dt.Rows[i]["login"].ToString();
                    lbllogout.Content = dt.Rows[i]["logout"].ToString();
                    
                }
           
           
            conn.Close();


:)
 
Share this answer
 

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