VIJEESH







ALTER PROCEDURE dbo.spCreateProgrammer
-- Add the parameters for the stored procedure here
@Title CHAR(10), @Name VARCHAR(60),
@NickName varchar(60), @HouseName VARCHAR(60),
@Street VARCHAR(60), @Post VARCHAR(60),
@Via VARCHAR(60), @Pin int,
@State VARCHAR(60) = 'Kerala', @Nationality VARCHAR(60)= 'Indian',
@EmailID VARCHAR(128)='', @Phone1 VARCHAR(14)='',
@Phone2 VARCHAR(14)='', @Sex CHAR(1) AS 
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.  
DECLARE @PID int;
SET NOCOUNT ON;  
-- test for exising record
IF (NOT EXISTS (SELECT NAME FROM PROGRAMMERS WHERE NAME=@Name AND HouseName=@HouseName))  
BEGIN  
SELECT @PID = Max(ProgrammerID) + 1 from Programmers;  
IF @PID = NULL
begin  
SELECT @PID=1;  
END  
INSERT INTO PROGRAMMERS(ProgrammerID) VALUES (@PID);  
END  
UPDATE PROGRAMMERS SET NAME=@Name, TITLE=@Title, NICKNAME=@NickName, HOUSENAME=@HouseName WHERE PROGRAMMERID=@PID; 
END


ALTER PROCEDURE dbo.spCreateSkillNames
@SkillName VARCHAR(60) AS
DECLARE @sid tinyint;
IF NOT EXISTS (SELECT SKILLNAME FROM SKILLS WHERE UPPER(SKILLNAME)=UPPER(@SkillName))
BEGIN  
SELECT @sid=MAX(SkillId) + 1 from SKILLS;  
INSERT INTO SKILLS (SkillId, SkillName) VALUES(@sid, @SkillName);
END
RETURN 

data base handler 
public void saveProgrammerDetails( String psTitle, string psName, string psNickname,string psHousename,string psStreet, string psPost,string psVia,string psState,string psNationality,string psEmailId, string psPhone1,string psPhone2,string psSex, int piPin,DateTime pBirthDate) { SqlCommand cmd = new SqlCommand("dbo.spCreateProgrammer", dbConnection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Title", title); cmd.Parameters.AddWithValue("@Name",psName); cmd.Parameters.AddWithValue("@NickName",psNickname); cmd.Parameters.AddWithValue("@HouseName", psHousename); cmd.Parameters.AddWithValue("@Street",psStreet); cmd.Parameters.AddWithValue("@Post", psPost); cmd.Parameters.AddWithValue("@Via",psVia); cmd.Parameters.AddWithValue("@Pin",piPin); cmd.Parameters.AddWithValue("@State", psState); cmd.Parameters.AddWithValue("@Nationality", psNationality); cmd.Parameters.AddWithValue("@EmailID",psEmailId); cmd.Parameters.AddWithValue("@Phone1",psPhone1); cmd.Parameters.AddWithValue("@Phone2",psPhone2); cmd.Parameters.AddWithValue("@Sex",psSex); cmd.Parameters.AddWithValue("@BirthDate", pBirthDate); cmd.ExecuteNonQuery(); }

///event handler
 protected void saveButton_Click(object sender, EventArgs e)
    {
        String psTitle, psName, psNickname, psHousename, psStreet, psPost, psVia,
            psState, psNationality, psEmailId, psPhone1, psPhone2, psSex;
        int piPin;
        DateTime pBirthDate;
        psTitle = titleList.Text.Trim();
        psName = nameTextBox.Text.Trim();
        psNickname = nickNameTextBox.Text.Trim();
        psHousename = houseNameTextBox.Text.Trim();
        psStreet = streetTextBox.Text.Trim();

        psPost = postTextBox.Text.Trim();
        if (psPost.Length == 0)
            psPost= postDropDownBox.Text;
        psVia = viaTextBox.Text.Trim();
        if (psVia.Length == 0)
            psVia = viaDropDown.Text;
        piPin = Convert.ToInt32(pinTextBox.Text);
        psState = stateTextBox.Text.Trim();
        if (psState.Length == 0)
            psState = stateDropDown.Text;
        psNationality = nationalltyDropDown.Text.Trim();
        if (psNationality.Length == 0)
            psNationality = nationalltyDropDown.Text;
        psEmailId = emailTextBox.Text.Trim();
        psSex = sexDropDown.Text;
        psPhone1 = phone1TextBox.Text.Trim();
        psPhone2 = phone2TextBox.Text.Trim();
        DateTime.TryParse(birthDateTextBox.Text.Trim(),out pBirthDate);
        
ProjectDataBaseHandler db = new ProjectDataBaseHandler();
        db.saveProgrammerDetails(psTitle, psName, psNickname, psHousename,
            psStreet, psPost, psVia,  psState, psNationality, psEmailId,
            psPhone1, psPhone2, psSex, piPin, pBirthDate);
    }