Click here to Skip to main content
15,903,719 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI
i created view for getting the maximum value of Stop-ID,So in StopNew() function i will add 1 to that Max Stop-ID
C#
public void StopNew()
       {

           this.MaxStopIDbindingSource.EndEdit();

           stopBindingSource.AddNew();
           this.MaxStopIDbindingSource.MoveFirst();
           ((DataRowView)this.stopBindingSource.Current).Row["nStopID"] = (int)((DataRowView)this.MaxStopIDbindingSource.Current).Row["nID"] + 1;

       }

but the max ID will not update in runtime, means view value will not updated in runtime.
Posted
Updated 4-Mar-11 23:25pm
v3

1 solution

I'm guessing a lot here, but the reason your view won't update at runtime is because you haven't updated your database yet - surely as soon as you commit the new record, your view will update?

If you need to be able to add multiple records, before committing your changes, then you'd have to keep a track of the id internally until you update.

This assumes this is a single-user database, of course.

For a multi-user database, if you need to know the value of a row;s ID without updating it first to the database, then you'd have to implement a new table, holding the next available (or last used) Id - and update that table every time you insert a record to your collection - that way every user gets the next available Id regardless.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900