TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
India Programmer
NA
54
0
How to set the auto increment value=true
Jan 14 2009 11:32 AM
Hello all,
I have a table with names 'Employee' with four field EmployeeId,Name,Address,Age
I have set the EmployeeId is Primary key.I want that EmployeeId field will be incremented automatically whenever adding any new records.
Codebehind for insert is:
{
DataClassesDataContext db = new DataClassesDataContext();
Employee emp = new Employee {Name = "James", Address = "India", Age = 24};
db.Employees.InsertOnSubmit(emp);
db.SubmitChanges();
ShowEmployee();
}
designer.cs:
[Column(Storage = "_EmployeeId", DbType = "Int NOT NULL", IsPrimaryKey = true,IsDbGenerated=true,CanBeNull=false)]
When I am running this application getting the following error:
Cannot insert the value NULL into column 'EmployeeId', table 'Habib.dbo.Employee'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Any help is highly appreciated.
Reply
Answers (
1
)
Requesting for project
Difference between Executable Path and Startup Path