fail to update a selected record

  • Thread starter Thread starter Tony WONG
  • Start date Start date
T

Tony WONG

The form call a selected record by "sqlDataReader"
then fill in textboxes by (TxtPhone.Text = reader("Dest_Addr").ToString)

i made the amendments to the textboxes and click Update button

strUpdate = "Update table set col1=@TxtPhone where ID='" & ID & "'"
cmdUpdate = New SqlCommand(strUpdate, myConnection)
MsgBox(TxtPhone.Text)
cmdUpdate.Parameters.AddWithValue("@TxtPhone", "852" +
TxtPhone.Text)

however the textbox return to old values

the record can be updated by erasing TxtPhone.Text
cmdUpdate.Parameters.AddWithValue("@TxtPhone", "852111111")

then the problem should be the textbox(TxtPhone.Text)

i try to change to SqlDataAdapter, dataset but still fail.

any ideas? Thanks a lot.

tony
 
after retest and retest, the form can be updated.

but i do not know why the form update with old value of textbox (me.load),
not the new value amended in the textbox

there is such statement at me.load
TxtPhone.Text = Dataset.Tables(0).Rows(0).Item(1).ToString

here is the button click event
Protected Sub BtnUpdate_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles BtnUpdate.Click
Dim strUpdate As String
Dim cmdUpdate As SqlCommand
Dim SMSID As String = "95542"
myConnection.Open()
strUpdate = "Update oshc_out set Dest_Addr=@TxtPhone where SMS_ID='"
& SMSID & "'"
cmdUpdate = New SqlCommand(strUpdate, myConnection)
cmdUpdate.Parameters.AddWithValue("@TxtPhone", "852" +
TxtPhone.Text)
cmdUpdate.ExecuteNonQuery()
myConnection.Close()

End Sub

grateful for help!
 
Back
Top