Question Update Database without re-enter all the information?

Chris Ewe

New member
Joined
Jul 21, 2010
Messages
3
Programming Experience
1-3
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.
VB.NET:
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
 
Last edited by a moderator:
when key in the latest data in address text box and hit submit button, the data in address text box remains the old data and does not update the database
 
Your post makes no sense:

There's a text box that you claim to ahve edited, and then you say it shows the old data - how can it? You just edited it. One statement or the other is false

-

Please also note that as soon as someone enters an address into your app that contains an apostrophe, your app is going to explode. Please read the PQ link in my signature. You should then seriously consider readying the DW1 link. Actually you should seriously consider upgrading your version of .NET to a modern version, then read one of the other links depending on what version you upgraded to.. Data access got a lot better in 2005/.NET2
 
Back
Top