•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 370,601 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,042 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 13292 | Replies: 10
![]() |
•
•
Join Date: Nov 2005
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Hi Paladine,
Am new to ASP.NET. I followed all the steps which you had given for Login Page and Registration Page. Everything is working properly. Thank you so much.
Paladin, I need one help from you, as per you steps I created one table called "tblUser". In this table U_id is auto number(In this same table I added additional two fields FirstName, LastName for Registration Page purpose). In your stored procedure sp_RegisterNewUser, you have used four fields username, password, Firstname and Lastname, so these four fields only inserting in the table. The first column U_id is inserting null value only. Can you advice me, how to auto increment U_id field while inserting every record.
My table structure:
Table Name: tblUser
U_id Integer (9)
U_Name VARCHAR(50)
U_Password VARCHAR(50)
FirstName VARCHAR(50)
LastName VARCHAR(50)
Advance Thanks Paladine.
Am new to ASP.NET. I followed all the steps which you had given for Login Page and Registration Page. Everything is working properly. Thank you so much.
Paladin, I need one help from you, as per you steps I created one table called "tblUser". In this table U_id is auto number(In this same table I added additional two fields FirstName, LastName for Registration Page purpose). In your stored procedure sp_RegisterNewUser, you have used four fields username, password, Firstname and Lastname, so these four fields only inserting in the table. The first column U_id is inserting null value only. Can you advice me, how to auto increment U_id field while inserting every record.
My table structure:
Table Name: tblUser
U_id Integer (9)
U_Name VARCHAR(50)
U_Password VARCHAR(50)
FirstName VARCHAR(50)
LastName VARCHAR(50)
Advance Thanks Paladine.
Sure thing. I am a little unclear as to what you are having an issue with, so let me say this (in hopes that it will help).
Ok, if you have the U_Id set to Autonumber then you have no need to increment it. Saying that, this means you do not pass a value to that column in an insert statement/query. In fact it is not required in any queries because Access handles it.
If you mean how do you increment it when if you set it to number. Well, I would create a temp table or even an array to store the last value used for the U_Id field and increment it by one prior to or part of an insert statement. If this is what you want more information on, then let me know and I can guide you through it.
Good luck...and happy coding
Ok, if you have the U_Id set to Autonumber then you have no need to increment it. Saying that, this means you do not pass a value to that column in an insert statement/query. In fact it is not required in any queries because Access handles it.
If you mean how do you increment it when if you set it to number. Well, I would create a temp table or even an array to store the last value used for the U_Id field and increment it by one prior to or part of an insert statement. If this is what you want more information on, then let me know and I can guide you through it.
Good luck...and happy coding
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
•
•
Join Date: Nov 2005
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Hi Paladine,
Thanks for your reply. Actually that U_id field should be incremented in front-end not in backend. Assume our table is empty, so while inserting we have to check whether our table contains record or not. If it is empty, we have to insert value for U_id. This value should be user defined, ie numeric or alpha numeric value.
Example:
Numeric value of U_id
1000
[or]
Alpha Numeric value of U_id
CAN00001
If the table already contains records, we have fetch the last record and auto increment that field.
Example:
Numeric value of U_id
1000
1001
1003
1004
1005
[or]
Alpha Numeric value of U_id
CAN00001
CAN00002
CAN00003
CAN00004
CAN00005
(In my table U_id is Integer, so pls first advice me how to increment the numeric value. Then if u can spend your valuable time for me, let me know how to auto-increment alpha numeric value)
Thanks Paladine
Thanks for your reply. Actually that U_id field should be incremented in front-end not in backend. Assume our table is empty, so while inserting we have to check whether our table contains record or not. If it is empty, we have to insert value for U_id. This value should be user defined, ie numeric or alpha numeric value.
Example:
Numeric value of U_id
1000
[or]
Alpha Numeric value of U_id
CAN00001
If the table already contains records, we have fetch the last record and auto increment that field.
Example:
Numeric value of U_id
1000
1001
1003
1004
1005
[or]
Alpha Numeric value of U_id
CAN00001
CAN00002
CAN00003
CAN00004
CAN00005
(In my table U_id is Integer, so pls first advice me how to increment the numeric value. Then if u can spend your valuable time for me, let me know how to auto-increment alpha numeric value)
Thanks Paladine
Ok, no problem, but in your original question you had stated autonumber, so I assume that was what you were wanting to increment.
So lets clear this up, from what you have said you are not going to auto increment, you just simply want to increment the U_Id field. But what concerns me is this statement : "This value should be user defined, ie numeric or alpha numeric value"
You are wanting to user to choose? I hope not, because the U_Id is the Primary Key (Unique Identifier) for the table.
Saying that I am not the Database police, but be warned any relationships with this table will not be maintain referential integrity.
So what I would do is this. You could create a table in the same databae, that would hold the table name, the last value used (for the U_Id column - the primary key column), and the amount to increment by (maybe you want to increment by 2's or 4's instead of by 1 ).
Then you create a function (called GetPrimaryKey) and have this function query the database to get the last value used, and amount to increment by columns (whatever you choose to call them), based on a parameter query which you pass the name of the table you want these values from. (Note: this whole scernario will accommodate multiple tables in the database to work on this premise). Then pass those values (or at least the last value used column value anyway) as part of your Insert statement.
So something like this:
pseudocode:
**note: Don't forget to update the tblPrimaryKeys Table with the newest "lastNumberUsed" value. **
I will let you try to work on that logic.
Basically the Logic Flows like this for the whole thing:
Before you goto insert data into a table (tblUser in our case), you call the function GetPrimaryKey, it goes to the tblPrimaryKeys with the name of the table you are inserting data into, retrieves the value of the LastNumberUsed, increments it by the amount you specify or the amount stored in the GetPrimaryKeys Table (whatever route you want to go - hard code or store in db?) and updates the GetPrimaryKeys table to reflect the new value of the LastNumberUsed, Your call to the GetPrimaryKey function returns the next available number for the U_Id column (in our case), and you include this as part of your insert statement. And this would only be on an insert... NOT ON AN UPDATE!
Hope this helps.
So lets clear this up, from what you have said you are not going to auto increment, you just simply want to increment the U_Id field. But what concerns me is this statement : "This value should be user defined, ie numeric or alpha numeric value"
You are wanting to user to choose? I hope not, because the U_Id is the Primary Key (Unique Identifier) for the table.
Saying that I am not the Database police, but be warned any relationships with this table will not be maintain referential integrity.
So what I would do is this. You could create a table in the same databae, that would hold the table name, the last value used (for the U_Id column - the primary key column), and the amount to increment by (maybe you want to increment by 2's or 4's instead of by 1 ).
Then you create a function (called GetPrimaryKey) and have this function query the database to get the last value used, and amount to increment by columns (whatever you choose to call them), based on a parameter query which you pass the name of the table you want these values from. (Note: this whole scernario will accommodate multiple tables in the database to work on this premise). Then pass those values (or at least the last value used column value anyway) as part of your Insert statement.
So something like this:
pseudocode:
Function GetPrimaryKey (strTableName as String) as Long ' Declarations ... ... ' Sets .... .... ' Logic GetPrimaryKey = .... "Select LastNumberUsed FROM tblPrimaryKeys WHERE tableName = tblUser" Return GetPrimaryKey End Function
**note: Don't forget to update the tblPrimaryKeys Table with the newest "lastNumberUsed" value. **
I will let you try to work on that logic.
Basically the Logic Flows like this for the whole thing:
Before you goto insert data into a table (tblUser in our case), you call the function GetPrimaryKey, it goes to the tblPrimaryKeys with the name of the table you are inserting data into, retrieves the value of the LastNumberUsed, increments it by the amount you specify or the amount stored in the GetPrimaryKeys Table (whatever route you want to go - hard code or store in db?) and updates the GetPrimaryKeys table to reflect the new value of the LastNumberUsed, Your call to the GetPrimaryKey function returns the next available number for the U_Id column (in our case), and you include this as part of your insert statement. And this would only be on an insert... NOT ON AN UPDATE!
Hope this helps.
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
•
•
Join Date: Nov 2005
Location: Mountain View, CA
Posts: 47
Reputation:
Rep Power: 3
Solved Threads: 1
Hi Ravi,
This solution looks very strange to me. If you requirement is just to increment the U_Id value on insert of new record, u can do that in the database level rather than using c# code.
How can you insert the alphanumeric value in to the U_id (numeric) field ? Anyway i can give both solution.
Hope this can help you.
Thanks,
Kedar
This solution looks very strange to me. If you requirement is just to increment the U_Id value on insert of new record, u can do that in the database level rather than using c# code.
How can you insert the alphanumeric value in to the U_id (numeric) field ? Anyway i can give both solution.
•
•
•
•
If u use the numeric datatype
in SQL Server:in other Databases:
- Open the table for designing.
- Select the U-Id field.Goto the properties of the field.
- Select Identity is Yes. Give Identity Increment as 1.
- Modify the table and Declare U_Id as Identity.
•
•
•
•
If you use alpha numericselect u_id from users where u_id in (select TOP 1 u_id
- first get the last record from the table using the sql query.
from users order by u_id desc)string userid = //Get from DB using the Query.
- This returns the last record. now u can generate next sequential userid with C# code.
userid= userid.Substring(3, userid.length);
int intval = Int32.Parse(userid);
intval += 1;
userid = "CAN" + inval.ToString();
Hope this can help you.
Thanks,
Kedar
Agreed, this method works, but from what I read, this doesn't meet his request.... but I think you solution is a preferred route.
•
•
•
•
Originally Posted by kedar_challa
Hi Ravi,
This solution looks very strange to me. If you requirement is just to increment the U_Id value on insert of new record, u can do that in the database level rather than using c# code.
How can you insert the alphanumeric value in to the U_id (numeric) field ? Anyway i can give both solution.
Hope this can help you.
Thanks,
Kedar
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
•
•
Join Date: Nov 2005
Location: Mountain View, CA
Posts: 47
Reputation:
Rep Power: 3
Solved Threads: 1
Like I said your reocmmendation is correct, but when he stated things like :
"This value should be user defined, ie numeric or alpha numeric value"
and
"Actually that U_id field should be incremented in front-end not in backend"
And your recommendation of:
This is how the table is already designed and built in the tutorials, so that was already a given which he didn't want.
Ikaravi also clearly states this : "Assume our table is empty, so while inserting we have to check whether our table contains record or not. If it is empty, we have to insert value for U_id. This value should be user defined, ie numeric or alpha numeric value."
So using Identity is not the method he wants to go with from these points.
Your second suggestion is clearly acceptable, but he also stated that "the value should be user defined..." Defined when? What is the restriction on this? So your solution does provide a method to accomplish this.
So yes, he could just do a Select statement on the table with U_Id set as a numeric only value, but I was providing a method for multiple tables set up this way as well as maintainability considerations. Not the only way to do this numeric field incrementation, but it works.
Hope this helps
"This value should be user defined, ie numeric or alpha numeric value"
and
"Actually that U_id field should be incremented in front-end not in backend"
And your recommendation of:
•
•
•
•
If u use the numeric datatype
in SQL Server:
in other Databases:
- Open the table for designing.
- Select the U-Id field.Goto the properties of the field.
- Select Identity is Yes. Give Identity Increment as 1.
- Modify the table and Declare U_Id as Identity.
This is how the table is already designed and built in the tutorials, so that was already a given which he didn't want.
Ikaravi also clearly states this : "Assume our table is empty, so while inserting we have to check whether our table contains record or not. If it is empty, we have to insert value for U_id. This value should be user defined, ie numeric or alpha numeric value."
So using Identity is not the method he wants to go with from these points.
Your second suggestion is clearly acceptable, but he also stated that "the value should be user defined..." Defined when? What is the restriction on this? So your solution does provide a method to accomplish this.
So yes, he could just do a Select statement on the table with U_Id set as a numeric only value, but I was providing a method for multiple tables set up this way as well as maintainability considerations. Not the only way to do this numeric field incrementation, but it works.
Hope this helps
•
•
•
•
Originally Posted by kedar_challa
Hi Paladine,
Could you please let me know his special requirement.
Thanks,
Kedar
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
•
•
Join Date: Nov 2005
Location: Mountain View, CA
Posts: 47
Reputation:
Rep Power: 3
Solved Threads: 1
Didn't say that.
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
- how to create an auto-increment process? (Oracle)
- How to auto increment reference number with char(9)? (VB.NET)
- auto incrememnt mysql (PHP)
Other Threads in the ASP.NET Forum
- Previous Thread: .aspx not working
- Next Thread: windows dialog


Linear Mode