0

I have one database and I want to get last value of column, and each time value will be updated after insertion here is sample database,

ID | Customer_Name |new_Total | Total
--------------------------------------
1  |     Mahesh    |   100    |  200
2  |     Mahesh    |   400    |  600 (200+400)
3  |     mahesh    |   100    |  700 (600+100)
2
  • do you mean any last updated value or last (max) value of a column? Please clarify. Commented Apr 16, 2015 at 6:04
  • You can easy use Sql command and it automatically updated for last column. do you need that command? Commented Apr 16, 2015 at 6:08

1 Answer 1

1

If i am getting you right you need to get last value of column i assume Total column.Here is you can read last value from database.

using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
{
 SqlCommand cmd = new SqlCommand("select Top 1 Total from tablename order by total desc", con);
 SqlDataReader rdr;
 con.Open();
 rdr = cmd.ExecuteReader();
 while (rdr.Read())
  {
   int total;
   int.TryParse(rdr["Total"].ToString(), out total);
  }

}

You will get value in total variable and you can use it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.