Solved

How to generate unique id in textbox.

Posted on 2012-03-20
3
184 Views
Last Modified: 2012-03-20
I have a table where records are to be entered.
Initially there are no records.
On frontend, i have a button Generate ID, and a textbox, i want when the user click on this button, automatically 1should come and so on.
This will happen at multiuser levels with one database.
How to put the number generated in textbox.

Please send code.

Table mststudents, id is the field which is primary key identity(1,1) is set.
textbox name is txtuin.
Connection name is con
please send the query.
0
Comment
Question by:searchsanjaysharma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37741394
>This will happen at multiuser levels with one database

You will have problem at some stage with this code.

Either use Identity column or use a stored procedure to do the insertions

Getting the ID is easier

command.commandtext = "Select IsNull(Count(*), 0) From mytable"

Dim cnt As Integer = command.ExecuteScalar()

txtID.Text = cnt + 1
0
 

Author Comment

by:searchsanjaysharma
ID: 37741421
identity is already set.
how to solve this.
s = "select isnull(max(id),0)+1  from mststudents"
will this be ok, if multiple people are doing the dataentry and all should have separate UIN.
I want all users should get separate uin
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37741630
Ok, ok.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question