fail to update a selected record

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
 
T

Tony WONG

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top