1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

retreiving value from sql server

Discussion in 'ASP' started by Carlos, Jun 10, 2009.

  1. Carlos

    Carlos New Member

    Joined:
    Dec 5, 2008
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    none
    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????
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    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].[B]Rows[ds.Tables[0].Rows.Count-1][0][/B].ToString()
    PS : You spell retreive incorrectly. Correct spelling is retrieve.
     

Share This Page