I am creating a update member page. I would like the page to auto retrieve the information he or she originally used while registering on my site and display them into the individual textboxes of the update profile page, this is to prevent the hassle to rekey in every individual details and allow the user to edit what he or she wants before it is updated into the database.

The problem that I encountered was not able to update the changes in the database. When key in the latest data in address text box and hit submit button, the old data in address text box remains and did not update the database

Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration

Partial Class UpdateEmployeeDetails
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Label1.Text = Session("Employee_ID")

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
            myConnection = New SqlConnection("data source=.\SQLEXPRESS; initial catalog=Human_Resource_Management;" & "integrated security=true")
            myCommand = New SqlCommand("Update Employee_DB Set Address = '" & Address.Text & "' where Employee_ID = '3344'", myConnection)

            MsgBox("Record has been updated")

        Catch exception As SqlException
        End Try

    End Sub

    Function updaterecords() As String
        Dim connetionString As String
        Dim sqlCnn As SqlConnection
        Dim sqlCmd As SqlCommand
        Dim sql As String

        Dim DBConn As New SqlConnection("data source=.\SQLEXPRESS; initial catalog=Human_Resource_Management;" & "integrated security=true")
        Dim DBCmd As New SqlCommand
        connetionString = "data source=.\SQLEXPRESS; initial catalog=Human_Resource_Management;" & "integrated security=true"
        sql = "Select * from Employee_DB where Employee_ID = '" & Session("Employee_ID") & "'"
        sqlCnn = New SqlConnection(connetionString)

        sqlCmd = New SqlCommand(sql, sqlCnn)
        Dim sqlReader As SqlDataReader = sqlCmd.ExecuteReader()
        While sqlReader.Read()

            Label1.Text = Session("Employee_ID")
            Label2.Text = sqlReader.Item(3)
            Session("sqlReader.Item(2)") = Address.Text

        End While

    End Function
End Class

Edited by Nick Evan: Fixed formatting

6 Years
Discussion Span
Last Post by G_Waddell

Does the user you are connecting to the database to have update permission on the Employee_DB table?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.