Today, I faced a problem which is related to banking application like account number. When I load the application to create new account for new customer then account number automatically increased by one from previously stored account. So, I want to pick last field value of Database table.
Let's see the example:
Let's see the example:
<Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="70,79,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
</Grid>
Code behind code
private void Button_Click(object sender, RoutedEventArgs e)
{
DatabaseEntities dbe = new DatabaseEntities();
var getlastrec = dbe.users.ToArray().LastOrDefault();
MessageBox.Show(getlastrec.Id.ToString());
}
Here DatabaseEntities is the context class. In this context class, we have public properties that is users. Through this we can get all records from user table, which is exist in model folder. Before doing this code, must to add EDMX file.