unique client Reference id automatic generation Asp.net | Vb.net - asp.net

My friends and I have started creating an e-commerce website using asp.net (vb.net). We are newbies and don't know much about it.
Can anybody show me how we can automatically generate unique reference id for each client who is purchasing the product from the website?

You can generate unique id's in database table by providing a column which will have a primary key or unique key assigned to it.and you can set auto increment property of that particular column on so it will increment automatically for each new customer entry.
You can also search the web in the mean time for better approach

There are a lot of ways and methods, but you can use the following command:
Dim user_id As Guid = Guid.NewGuid()
That will generate a unique Id for you.
You can also generate the new id automatically in your database table. Just make sure to create column with data type uniqueidentefier and assign it a default value property newid()

Related

Microsoft Project: Is it now possible to set or change a Unique ID of a task?

In Microsoft Project, the only way to reset Unique IDs in the past was to change all Unique IDs in a file. This is rarely done but possible to do if someone happened to want the schedule to have Unique IDs in ascending order like the Task IDs. Recently, I was asked if it was now possible to set or change the Unique ID of a singular task. I don't believe that you can and I haven't found any documentation from Microsoft that says that this is possible. Does anyone know if you can in fact set or change the Unique ID of a single task?
No. Nothing has changed--the Unique ID is a calculated field which is another way of saying it's unchangeable by the user.
A very quick search leads to the documentation: Unique ID fields which states:
The Unique ID field contains the number that Microsoft Office Project automatically designates whenever a new task, resource, or assignment is created in the current project. This number indicates the sequence in which the task, resource, or assignment was created, regardless of placement in the schedule.
There are several categories of Unique ID fields.
Data Type Integer
Unique ID (task field)
Entry Type Calculated
How Calculated As you create new tasks, Project adds a unique number to each task in the project. This number is unique in that it is never rearranged or reused if the task is moved or deleted.

Getting value of auto incremented column in advance

I am using the entity framework in asp .net. In the database, I have a table named Post in which id is auto incremented. Now, before adding a new post, I want to know which id will be assigned to this post.
One way for you get your goal is use a SQL Server Procedure get max id from your table post and plus 1 and you will get you next Id.. this is a waste way for get your goal
SELECT MAX(ID) FROM POST
For how using store procedures into EF read this link maybe help you
http://www.devtoolshed.com/using-stored-procedures-entity-framework-scalar-return-values

how to generate unique id per user?

I have a webpage Default.aspx which generate the id for each new user after that the id will be subbmitted to database on button click on Default.aspx...
if onother user is also entering the same time the id will be the same ... till they press button on default.aspx
How to get rid of this issue...so that ... each user will be alloted the unique id ...
i m using the read write code to generate unique id ..
You could use a Guid as ids. And to generate an unique id:
Guid id = Guid.NewGuid();
Another possibility is to use an automatically incremented primary column in the database so that it is the database that generates the unique identifiers.
Three options
Use a GUID: Guid.NewGuid() will generate unique GUIDs. GUIDs are, of course, much longer than an integer.
Use intelocked operations to increment a shared counter. Interlocked.Increment is thread safe. This will only work if all the requests happen in the same AppDomain: either process cycling on a refresh of the code will create a new AppDomain and restart the count.
Use an IDENTITY column in the database. The database is designed to handle this, within the request that inserts the new row, use SCOPE_IDENTITY to select the value of the identity to update in memory data (ORMs should handle this for you). (This is SQL Server, other databases have equivalent functionality.)
Of there #3 is almost certainly best.
You could generate a Guid:
Guid.NewGuid()
Or you could let the database generate it for you upon insert. One way to do this is via a Sequence. See the wikipedia article for Surrogate Keys
From the article:
A surrogate key in a database is a unique identifier for either an entity in the modeled world or an object in the database. The surrogate key is not derived from application data.
The Sequence/auto-incremented column option is going to be simpler, and easier to remember when manually querying your DB (during debugging), but the DBA at my work says he's gotten 20% increases in performance by switching to Guids. He was using Oracle, and his database was huge, though :)
I use a utility static method to generate id's, basically use the full datetime(including seconds) and generate a random number of say 3 or 4 characters and return the whole thing, then you can save it to the database.

Adding an integer ID to ASP.NET Forms Authentication

In the standard forms authentication, users are identified by a Guid. I want to give my users an UserId of type int (doesn't have to be the primary key, just something to do lookup's on).
Is it safe to add an additional column to the aspnet_users table, or should I create a new table which FKs to the UserId column and has a Unique column which generates the integer ID?
The later sounds like a bad performance hit to take just for the sake of an int!
EDIT
I want to create URLs like those on stackoverflow. eg. https://stackoverflow.com/users/23590/greg-b where the User ID is an int. For that reason I don't want to use Guids.
I'd create profiles and store the associated urlID there. Web Forms don't have Profiles available out of the box, but you can see a workaround here:
http://www.codersbarn.com/post/2008/06/01/ASPNET-Web-Site-versus-Web-Application-Project.aspx
The advantage of using Profiles is that you can tap into all the existing logic and won't have to write as much custom code yourself, aside from constructing the URL.
You could combine this with Routing for friendly URLs, if you're using ASP.NET 3.5 or up.
UPDATE: kinda similar question:
Shorter GUID using CRC

Using IPrinciple.Identity.Name as a key in a dataBase to identify user's rows

I'm writing a small intranet app that uses Windows Authentication and Asp.Net MVC.
I need to store various bits of data in a db against each user.
As far as I can tell the IPrinciple object does not seem to have something like a unique id. So I was thinking I could just use User.Identity.Name as a unique value to identify rows in my db.
Is this a bad idea? Is there an alternative to this approach?
Thanks for any help.
I would create a User table that included an identity column as the id. When a person accesses the site, I would check the user table for that individuals unique id, and read it if it exists, or insert a new row if the user is new.
Login names can be long, and that could affect your indexes depending on the expected size of your data.

Resources