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") updaterecords() 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 Try myConnection = New SqlConnection("data source=.\SQLEXPRESS; initial catalog=Human_Resource_Management;" & "integrated security=true") myConnection.Open() myCommand = New SqlCommand("Update Employee_DB Set Address = '" & Address.Text & "' where Employee_ID = '3344'", myConnection) myCommand.ExecuteNonQuery() MsgBox("Record has been updated") myConnection.Close() Catch exception As SqlException MsgBox("Failed") 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 DBConn.Open() 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) sqlCnn.Open() 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