I have one user form in which users login & can view all there information which is already stored in database. So onPageLoad I have select query. Now If user wants to update any record from textfield they can edit but here the information I modify is not making update in database. here is my code.

I tried to breakpoint on my update query & under that I do not see the updated information which I fill. It takes the existing one only.

OnPageLoad

Private Sub list_business_hospital_Load(sender As Object, e As EventArgs) Handles Me.Load

        If Not IsPostBack Then
            Try
                Dim str As String = "SELECT * FROM  hospitals WHERE username='" + Server.HtmlEncode(Request.Cookies("chkusername").Value) + "';"
                con.Open()
                Dim cmd As New MySqlCommand(str, con)
                Dim da As New MySqlDataAdapter(cmd)
                Dim dt As New DataTable
                Dim lblservice As New Label
                For Each chk As ListItem In servicesList.Items
                    If chk.Selected = True Then
                        lblservice.Text = String.Concat(lblservice.Text + ",", chk.Value)

                    End If
                Next

                da.Fill(dt)
                con.Close()
                TextId.Text = dt.Rows(0)("hospitalID").ToString
                businessName.Text = dt.Rows(0)("name").ToString
                welcome.Text = dt.Rows(0)("name").ToString
                subCat.Text = dt.Rows(0)("subcategory").ToString
                contactPerson.Text = dt.Rows(0)("contactPerson").ToString
                websiteName.Text = dt.Rows(0)("websiteName").ToString
                emailName.Text = dt.Rows(0)("email").ToString
                phone1.Text = dt.Rows(0)("phone1").ToString

            Catch ex As Exception
                Response.Write(ex)
            End Try
        End If
    End Sub

Update Button

Private Sub updateInfo_Click(sender As Object, e As EventArgs) Handles updateInfo.Click
        Try
            Dim con As New MySqlConnection
            Dim query As New MySqlCommand
            con.ConnectionString = ConfigurationManager _
                .ConnectionStrings("conio").ConnectionString()
            query.Connection = con
            con.Open()
            query.CommandText = "UPDATE hospitals SET name = '" + businessName.Text + "', contactPerson = '" + contactPerson.Text + "', websiteName = '" + websiteName.Text + "', email = '" + emailName.Text + "', phone1 = '" + phone1.Text + "' WHERE hospitalID = '" & TextId.Text + "'"
            query.ExecuteNonQuery()
            con.Close()
            Response.Write("<script language='javascript'>alert('Information updated successfully.');</script>")
        Catch ex As Exception
            Response.Write(ex)
        End Try
    End Sub

Related posts

Recent Viewed