Click here to Skip to main content
15,908,842 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
1. I am using Visual Studio 2010 and MSSQL 2005. 2. I am developing a web interface for already exiting application to enable certain internal customers login and retrieve their own data. 3. They will check the retrieved data to be sure the existing data is ok as captured. 4. If it needs modification, they will go ahead to modify the retieved data on the controls on the form. 5. When done, they will submit for update. The submit event should UPDate tblEmployeeInformation table and INSERT audit trail in the tblAuditTrailHuresLive. 6. If it goes through, the modified data should be displayed for confirmation. 7. When done, they will use confirm button to certify the displayed data. 8. Each form should keep session which can terminate after 5minutes of idle time.

code behind for BIO-Data Form:
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    ' This code executes when the page is first loaded.
    If Session("empcode") <> "" Then
        lblStaffCode.Text = Session("empcode")
        staffid = CInt(lblStaffCode.Text)
        lblUserName.Text = globalusername
        sqlstr = "SELECT Surname,Firstname,Middlename,Initials,DOBDay,DOBMonth,DOBYear,Sex,MaritalStatus,BloodGrp,Genotype,PlaceofBirth,HomeTown,State,LGA,Nationality,Religion FROM tblEmployeeInformation WHERE EmpCode='" & staffid & "'"
        displayrecord()
    End If
End Sub

Private Sub displayrecord()
    'This retrieves data of some fields out of many and render on controls on the BioData form. the idea is to make modifications on the display data and update.
    Call OpenCon()
    Try
        Dim comStafffd As SqlCommand = New SqlCommand(sqlstr, cnSUSU)
        Dim objReader As SqlDataReader
        DAFD2 = New SqlDataAdapter
        DAFD2.SelectCommand = comStafffd
        DSFD2 = New DataSet
        DAFD2.Fill(DSFD2, "tblEmployeeInformation")

        objReader = comStafffd.ExecuteReader()

        objReader.Read()
        txtSurname.Text = objReader("Surname")
        txtFirstname.Text = objReader("Firstname")
        txtMiddlename.Text = objReader("Middlename")
        txtInitials.Text = objReader("Initials")
        txtDay.Text = objReader("DOBDay")
        cboMonth.SelectedValue = objReader("DOBMonth")
        txtYear.Text = objReader("DOBYear")
        txtSex.Text = objReader("Sex")
        txtMaritalStatus.Text = objReader("MaritalStatus")
        txtBloodgroup.Text = objReader("BloodGrp")
        txtGenotype.Text = objReader("Genotype")
        txtPlaceofbirth.Text = objReader("PlaceofBirth")
        txtHometown.Text = objReader("HomeTown")
        txtState.Text = objReader("State")
        txtLGA.Text = objReader("LGA")
        txtNationality.Text = objReader("Nationality")
        txtReligion.Text = objReader("Religion")
        objReader.Close()

        If txtSex.Text = "M" Then
            optMale.Checked = True
        ElseIf txtSex.Text = "F" Then
            optFemale.Checked = True
        End If

        If txtMaritalStatus.Text = "MARRIED" Then
            optMarried.Checked = True
        ElseIf txtMaritalStatus.Text = "SINGLE" Then
            optSingle.Checked = True
        ElseIf txtMaritalStatus.Text = "DIVORCED" Then
            optDivorced.Checked = True
        ElseIf txtMaritalStatus.Text = "WIDOWED" Then
            optWidowed.Checked = True
        ElseIf txtMaritalStatus.Text = "WIDOWER" Then
            optWidower.Checked = True
        ElseIf txtMaritalStatus.Text = "SEPERATED" Then
            optSeparated.Checked = True
        End If

    Catch ex As Exception
        lblError2.Text = ("Error occurred: " + ex.Message)
    Finally
        cnSUSU.Close()
    End Try
End Sub


I will appreciate if you guys helps me sort out the problem. The displayrecord procedure work when the page loads the first time. At run time the codes do not through exception but only post into tblAuditTrailhuresLive but does not for tblEmployeeInformation. The session tracking is not working properly across the pages. I also suspect "if Not IsPostBack ..." is not used on the page because I am yet to appreciate it. Session is not properly controlled. The logout link/button is not done yet.(Sorry i had to post long post. i would have attached the files rather. Bera with me.)
Posted
Updated 24-Dec-11 10:26am
v2
Comments
[no name] 24-Dec-11 16:27pm    
Edited to remove useless code. You don't need to post your entire application when asking a question, only the relevant parts are necessary.

"I also suspect "if Not IsPostBack ..." is not used on the page because I am yet to appreciate it"

IsPostBack is not used, you have no code that uses it. What you suspect it and why have you not taken the time to learn properly?

You have a considerable amount to learn. The markup and code-behind could be cleaned up dramatically by using DataBinding.

Use smaller discrete methods rather than one massive block of code in one method.

In cmdSubmit_Click you use parameters with your SQL command, yet in the EditRec you use string concatenation with unvalidated raw user input. NEVER use this method EVER. You have opened yourself to SQL injection attacks and made your application and data extremely vulnerable. There is a large volume of information about this.
 
Share this answer
 
Thanks Mark for ur response.

If you can give me bits of codes to take care of ur observations, that will help. For instance, what will be right IsPostBack block?

In cmdSubmit_Click I used parameters with your SQL command to test in order to be sure is not the way I presented it in the EditRec.

Any section u can assist will be most appreciated. Thanks.
 
Share this answer
 
v2
Comments
André Kraak 25-Dec-11 4:47am    
If you have a question about or comment on a given solution use the "Have a Question or Comment?" option beneath the solution. When using this option the person who gave the solution gets an e-mail message and knows you placed a comment and can respond if he/she wants.

Please move the content of this solution to the solution you are commenting on and remove the solution.
Thank you.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900