Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i cant use database
vb.net i am using

What I have tried:

whats that code for it
have fix it for me
how to do it
Posted
Updated 5-Jul-17 19:42pm
Comments
Karthik_Mahalingam 6-Jul-17 1:36am    
win ? web ??

1 solution

That's going to depend on exactly what you need to do: for example if you need a multiuser system where each from instance needs to be unique then that really requires a different approach from a single user app (and that would be handled differently depending on whether the uniqueness needs to be preserved from run to run of the app).

But in general, it's a bad idea to assign a unique number when a form is opened: it should only be assigned when data is saved, not when the form it opened so it can be entered. There are good reasons for this, primarily related to multiuser concerns where it frequently ends up with number duplication; but not just multiuser: it can cause problems in single user systems if numbers have to be truly sequential and they are allocated before data is saved.

So start by thinking about exactly what the number is for, and why you need it: who is going to use it, and what are they going to do with it? Do they need to see it? Why? In nearly all cases, it's an internal number that users never need to know and don't care about - it's only used to "back reference" data entry later, and is completely unnecessary before data entry is completed.

Once you've worked out how it's needed, start thinking: if it's multiuser, then you need a single central system to allocate them which is accessible from all "client" stations via a network or the internet. This should not be internal to your app at all!
For single user versions that need to be unique across runs, you need some form of data persistence - which means you need to look at what persistent data you already have and add the new values to that.
For date which only has to be unique within the current execution of the app, it's trivial: a static variable within the Form class which gets incremented each time it's used.

But we can't do anything but the trivial for you - we have no idea about how the rest of your app works!
 
Share this answer
 
Comments
Arnav121 7-Jul-17 1:33am    
Or how can i do it with database?
OriginalGriff 7-Jul-17 2:30am    
That's easy: set up an INT column, and make it an IDENTITY column: the database will then do it all for you when you insert a new row.
Google "SQL Identity" and you'll get loads of info.

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