Click here to Skip to main content
12,694,842 members (32,646 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
I am working on a webbased application(Employee registration form). In which I am storing user information in SQL server. I have text box to insert the employ id no., on textbox textchange event (it will verify the id is valid or not,from another table where only employ idno.s are stored), If it is a valid id no. then it will allow to enter other details like(Ename, address, contact no:,...etc). On clicking submit button all this information will be saved in database table called EmpRegister. In EmpRegister table I have primary key on EID column, if an employee try to register for more than one time, it is giving server error.
Can anybody help me regarding this, On text change event two things should happen (1. It should check it is a valid id or not fro EIDS table of database, 2. If that id is already registered in EmpRegister table,then it should not give server error, Instead we can give an error message that "Already Registered").
Kindly help me with the code, I am new to programming. Thanks in advance.
Posted 23-Jan-13 6:22am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

do your validations...before inserting check employee is registered or not..exampal

cmd=("Select count(*) from employee where emp_name='"+txtEmpName.Text+"'",con);
Int32 hh=convert.ToInt32(cmd.ExecuteScaler());

//your insert coading
//give alert message employee already registered

change select as per your requirement i.e in where check EID or empname...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Just define EID as a primary key field and while inserting a data it will check an unique and not null data from table.
and if user is already existing with a same EID it will throw an error.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

I am not sure why you would need another table to store Employee Id numbers. You can include everything in one table and you can use IDENTITY (Property)[^] to auto generate the EId column. Here is a sample of how your table would look.
   EId INT IDENTITY(1,1) CONSTRAINT PK_EmpRegister PRIMARY KEY, --This is the primary key that is auto generated
   EmployeeId VARCHAR(100), --This is the employee ID entered by user.
   EName VARCHAR(100),
   Address VARCHAR(100),...

When User enters the Employee Id you can check if it exists or not like this
SELECT COUNT(*) FROM EmpRegister WHERE EmployeeId = 'Value entered by user'
If the EmployeeId entered by user already exists the count will return a non zero value else it will return 0.
2012programmer 23-Jan-13 15:19pm
First of all I thank you for your help.
For example, there is 1500 employees. These employee id's are stored in a table(EIDS), But My requirement is to register only 50 employes(EmpRegister table) from those 1500 employees. I need two types of validations, 1. The user entered id must be present in EIDS table, 2. EmpRegister table should not include duplicate records(For this purpose "EID" column of EmpRegister table has a primary key- this is working fine, but if there is duplicate value try to insert into database table- it is giving Server Error in the browser, this is not looking good in the browser, what I need is just give an alert message that "Already Registered".
__TR__ 24-Jan-13 1:37am
I am having difficulty understanding your requirement.
What is the criteria for registering only 50 employees out 1500 employees?

What if an employee enters an Id that is present in EIDS table but the Id was assigned to someother employee. How do you plan to handle such a scenario ?

What exactly is it that you are trying to do here ?
2012programmer 24-Jan-13 15:32pm
I am planning a training program for employees, for that employees will register on a web page. If there 1500(for example), but the training program is designed for 50 employs only.
My requirement: Somebody can fill my database with garbage values. To avoid this, I have EIDS table in which all employ ids are stored, If a user try to enter gargabe value, then it will check with EIDS table then it will allow you to enter other details. This is working fine. But another requirement if an employ try to re-register it is giving "Server Error", Instead of server error can we provide an alert box with "already registered"
__TR__ 25-Jan-13 2:13am
That should be easy. Just find out if the user has already registered before doing an insert. If the record is already inserted don't do anything in database and show a message to user saying s/he has already registered, else insert the record. Let me know if you have any questions. Also it would be helpful if you show the table structures when ask your question.
2012programmer 26-Jan-13 2:35am
I am inserting the record when a user click on button. But Iam checking the userid is correct or not in text change event. In text change event only can I check the user is already registered or not.
__TR__ 28-Jan-13 10:50am
In that case just pass the user id entered in the textbox to database and check if it exists in the table.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100