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)
Nadeem_MK
  • 7,533
  • 7
  • 50
  • 61
Divyang Desai
  • 7,483
  • 13
  • 50
  • 76

1 Answers1

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.

Mairaj Ahmad
  • 14,434
  • 2
  • 26
  • 40