473,837 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

check the code urgent

30 New Member
strSql = "SELECT ISNULL(max(subs tring(User_ID,2 ,len(User_ID))) + 1,'100') FROM Users";
sqlCmd.CommandT ext = strSql;
sqlDr = sqlCmd.ExecuteR eader();
sqlDr.Read();
UserID = "U" + sqlDr.GetValue( 0);

after this i write insert query.

in that insert query my user_Id value will be like this U100,U101... upto U1000. upto this we don't have any problems. after U1000 no one can't insert any record i got error

Violation of PRIMARY KEY constraint 'PK__Users__656 C112C'. Cannot insert duplicate key in object 'Users'. The statement has been terminated.

this problem is due to above select query generating User_ID. it can't generate U1001 ... values
could any one please give me any suggessions very urgent
Mar 6 '08 #1
5 1695
kenobewan
4,871 Recognized Expert Specialist
My friend, the whole point of making id a primary field is to ensure that they are protected. Depending on which db you are using there are methods for auto incrementing the id so that this situation never arises. Redesign your db or prepare for alot of pain in the future.
Mar 6 '08 #2
shweta123
692 Recognized Expert Contributor
Hi,

Are you using any loop for getting the UserID and inserting UserID value into the table? Because of which you are getting the error for insertion. Can you post more details about your code?

strSql = "SELECT ISNULL(max(subs tring(User_ID,2 ,len(User_ID))) + 1,'100') FROM Users";
sqlCmd.CommandT ext = strSql;
sqlDr = sqlCmd.ExecuteR eader();
sqlDr.Read();
UserID = "U" + sqlDr.GetValue( 0);

after this i write insert query.

in that insert query my user_Id value will be like this U100,U101... upto U1000. upto this we don't have any problems. after U1000 no one can't insert any record i got error

Violation of PRIMARY KEY constraint 'PK__Users__656 C112C'. Cannot insert duplicate key in object 'Users'. The statement has been terminated.

this problem is due to above select query generating User_ID. it can't generate U1001 ... values
could any one please give me any suggessions very urgent
Mar 6 '08 #3
kenobewan
4,871 Recognized Expert Specialist
Hi,

Are you using any loop for getting the UserID and inserting UserID value into the table? Because of which you are getting the error for insertion. Can you post more details about your code?
You actually support this practice? Isn't there a danger of ending up with non unique id numbers? I experienced this pain once when I joined a company. What is the design of the table?
Mar 7 '08 #4
shweta123
692 Recognized Expert Contributor
Hi,

You should generate the UserIds from the code only if :

1) You do not want only numeric values in the ID. i.e.
You want to take character(e.g. "U") in the beginning of the userid.
2) You want to start generate IDs from perticulat digit.(e.g. 100)
3) You do not want the ID values which are sequential.
4) You can get more no of unique ID combinations if you make ID using letters and numbers.
Mar 7 '08 #5
kenobewan
4,871 Recognized Expert Specialist
Hi,

You should generate the UserIds from the code only if :

1) You do not want only numeric values in the ID. i.e.
You want to take character(e.g. "U") in the beginning of the userid.
2) You want to start generate IDs from perticulat digit.(e.g. 100)
3) You do not want the ID values which are sequential.
4) You can get more no of unique ID combinations if you make ID using letters and numbers.
At the risk of appearing argumentative:
1) Not sure when this would be desirable, why would you want this?
2) I created a default of 3000 once, in sql it allowed me to set the initial number.
3) An auto increment could also be set >1.
4) True and a case can be made for using secure id's that are alphanumerical, but again doing this in the application is risky.

Guess my point was generate the id in the database, even if it is by a stored procedure, rather than the application.
Mar 8 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

17
2771
by: Dave Smithz | last post by:
Hi there, A PHP application I built has a section which lists a number of members to a club whose names each appear with a check box beside them that can be ticked. These check boxes are part of a form which amongst other submit buttons has a one particular submit button that if checked will send the form data (using GET) to a script that will email all the checked members.
3
6485
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from the socket is missing the last character (line feed). When the same text is sent without the urgent flag set, all of the characters are read. I'm reading the data using the blocking read call of the network stream class. The .NET...
8
5237
by: Allan Ebdrup | last post by:
I'm writing some code where I have have a class that implements 4 methods (class A) I only want to call these methods from the base class if they have been overridden in a sub class (Class B) I guess I could have some properties that specify wether to call the methods, but I would like to call them automatically when they are overridden, how do I do this using reflection? Class A { private void methodX()
11
520
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. It is greatly appreciated. Is there a way to programmatically check for .NET Framework versions installed on the computer? -- Michael Bragg, President eSolTec, Inc. a 501(C)(3) organization MS Authorized MAR looking for used laptops for developmentally disabled.
12
5936
by: Ryan | last post by:
Is there anyway to enable spell-checking for user input in a Text Box? Either auto spell-check or create a spell-check button. Using VB 2005.
10
8043
by: Dieter Pelz | last post by:
Hallo, what is the best way to check the installation of mfc80 and vcrt sidebyside assemblies? Best Regards, Dieter Pelz
1
1335
by: sureshreddy | last post by:
Hi friends, I am working on project in which i need a color change for the selected cell when i check the checkbox. when i uncheck it the color should also disappear. If you didn't understand what i said plz go to www.clickjobs.com and check a checkbox and you can undertand. If possible plz send me the code as it is urgent. Thanks in advance SureshReddy
15
3078
by: Brian Simmons | last post by:
Is there an easy way to check to see if a file is in use? I want to open a CSV file from my .NET2 program, and write to it. However, the file could be in use by another program. If that is the case, I don't want to attempt to write to it, just abort. Thanks, Brian
2
7673
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the PasswordRecovery with a Password reset required; a temporary password is sent to the account on file. I want an extra layer of security to accommodate the very unlikely contingency that someone's e-mail account is compromised. Challenging with the...
0
9833
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10867
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10562
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10617
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10263
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6989
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5842
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4469
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3122
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.