i have a problem.. i just can't see where i did go wrong..
when my page loads, i want the name and email appear in the textbox so that user can edit their name and email...but then, it doesn't update the record, but continue to save the old value of name and email appear in the textbox when page load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConnection As String = ConfigurationSettings.AppSettings("ConnectionString")
Dim sqlConn As New SqlConnection(strConnection)
Session("sRespondentID") = Request.QueryString("RespondentID")
sqlConn.Open()
If Session("sRespondentID") <> "" Then
Dim sql As SqlCommand = New SqlCommand("SELECT * FROM Respondent WHERE RespondentID='" & Session("sRespondentID") & "'", sqlConn)
Dim dr As SqlDataReader
dr = sql.ExecuteReader
While dr.Read
txtName.Text = dr("Name").ToString
txtEmail.Text = dr("Email").ToString
End While
dr.Close()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strConnection As String = ConfigurationSettings.AppSettings("ConnectionString")
Dim sqlConn As New SqlConnection(strConnection)
sqlConn.Open()
Dim cmd2 As String = "UPDATE Respondent SET Name='" + txtName.Text + "', Email='" + txtEmail.Text + "' WHERE RespondentID = '" & Session("sRespondentID") & "'"
Dim MyCommand2 As SqlCommand = New SqlCommand(cmd2, sqlConn)
If MyCommand2.ExecuteNonQuery Then
Response.Redirect("maillist.aspx")
Else
lblMsg.Text = "Record cannot be updated at this moment."
End If
End Sub
please help me..i cannot see where my mistake