Go4Expert

Go4Expert (http://www.go4expert.com/)
-   ASP (http://www.go4expert.com/forums/asp/)
-   -   retreiving value from sql server (http://www.go4expert.com/forums/retreiving-value-sql-server-t17934/)

Carlos 10Jun2009 17:11

retreiving value from sql server
 
Hi! i want to retreive value from a table named costomer, this code is working , but there is a problem that is always give the first row value, and i required the last inserted value.

SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString01"].ToString();
SqlCommand cmd = new SqlCommand("select cost_id from costomer",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,"costomer");
string temp = ds.Tables[0].Rows[0][0].ToString()

can anyone tell me how to retreive last value of table????

SaswatPadhi 10Jun2009 18:32

Re: retreiving value from sql server
 
Obviously Rows[0][0] will give the first value.
If you want the Item[0] from last row, I think this will work :

Code:

SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString01"].ToString();
SqlCommand cmd = new SqlCommand("select cost_id from costomer",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,"costomer");
string temp = ds.Tables[0].Rows[ds.Tables[0].Rows.Count-1][0].ToString()

PS : You spell retreive incorrectly. Correct spelling is retrieve.


All times are GMT +5.5. The time now is 21:05.