0

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....

3 Answers 3

1

You can make the object Unique by using Guid type. emp1.Guid = Guid.NewGuid();

Sign up to request clarification or add additional context in comments.

Comments

1

There are a couple of different ideas here:

  1. 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.

  2. 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.

Comments

1
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.