Reputation: 869
In my asp.net web applicaiton I am using objects to add infomation to database something like this
Employee emp1 = new Employee()
emp1.name = "something"
emp1.age = some age
InsertEmployee(emp)
This code works fine. But however if multiple users are trying to insert the employee data then data gets mixed up.
User then calls up and says , "The age I entered is different from what it is showing for employee XXX.
How to fix this ? Whats the good method to make the object unique ?.
Thanks....
Upvotes: 0
Views: 113
Reputation: 32661
User then calls up and says , "The age I entered is different from what it is showing for employee XXX.
How are you updating the user results?
How to fix this ? Whats the good method to make the object unique ?.
You need to add primary key in your database. And do all your database operations against that primary key. You can read about SQL Keys here .Example
update yourTable
SET
YourColumnName = YourValue
Where
tableId = Idofthisemployee
Upvotes: 1
Reputation: 3313
You can make the object Unique by using Guid type. emp1.Guid = Guid.NewGuid();
Upvotes: 1
Reputation: 11910
There are a couple of different ideas here:
Primary key in the database. In this case, you could use an integer value for the ID and this is a way to keep all the employees sorted in a relatively clean manner using some of SQL Server's built-in functionality.
GUIDs. In this case, you'd assign a new GUID to each employee and have this be a unique value for each employee. This can be done in the DB though you could also do it in the C# code if you wanted.
Upvotes: 1