Please, read my comment to the question and have a look at below sample (using
Linq[
^]):
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("ID", System.Type.GetType("System.Int32"));
dt.Columns.Add(dc);
dc = new DataColumn("UserId", System.Type.GetType("System.String"));
dt.Columns.Add(dc);
dc = new DataColumn("Password", System.Type.GetType("System.String"));
dt.Columns.Add(dc);
dt.Rows.Add(new Object[]{1, "vvv", "v"});
dt.Rows.Add(new Object[]{2, "asd", "a"});
//max id
dt.Rows.Add(new Object[]{4, "sdasd", "r"});
//last row ;)
dt.Rows.Add(new Object[]{3, "dsa", "r"});
int lastid = dt.AsEnumerable().Select(x=>x.Field<int>("Id")).Last();
//returns 3
int maxid = dt.AsEnumerable().Max(x=>x.Field<int>("Id"));
//returns 4
As you can see, last row does not mean
Max(ID)
.
Depending on what you want to achieve, change the code to your needs ;)