473,385 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

check the code urgent

30
strSql = "SELECT ISNULL(max(substring(User_ID,2,len(User_ID))) + 1,'100') FROM Users";
sqlCmd.CommandText = strSql;
sqlDr = sqlCmd.ExecuteReader();
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__656C112C'. 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 1667
kenobewan
4,871 Expert 4TB
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 Expert 512MB
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(substring(User_ID,2,len(User_ID))) + 1,'100') FROM Users";
sqlCmd.CommandText = strSql;
sqlDr = sqlCmd.ExecuteReader();
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__656C112C'. 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 Expert 4TB
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 Expert 512MB
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 Expert 4TB
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
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...
3
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...
8
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...
11
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,...
12
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
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
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...
15
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.