Weird saving behaviour

bonedoc

Well-known member
Joined
May 4, 2006
Messages
112
Programming Experience
Beginner
I have a routine that saves data in textboxes on my form. That works great. But , I need to clear the textboxes after they have been saved. This is what I am doing in my private sub:

SaveData()
ResetForm()

The first one saves the values in the textboxes, and the second converts all the textboxes text to "". Well, for some odd reason, it saves all of the data as "".....and I am saving the textbox text before I clear them. It appears that this would be impossible because it has to do the savedata() before it moves to the resetform(). Can someone tell me what may cause this behaviour, or if there is another way to make it wait to clear the boxes after the data is saved?
 
Here is my code.It is pretty easy. The saving does work fine, but then when I add the ResetForm() , the daabase somehow saves the "" values instead of text value that were in there. Strange.

Private Sub KeysArePressed(ByValsender as system.object, byval e as system.windows.forms.KeysPressEventsArg) Handles TextBox1.KeysPress

if e.KeyChar = Microsoft.VisualBasic.ChrW(13) then

SaveData()
ResetForm()

End If
End Sub

Private Sub SaveData()

daPeoplesData.UpdateCommand.Parameters.Item("PersonID").Value = m_CurrentPerson
daPeoplesData.Update

End Sub

Private Sub ResetForm()

TextBox1.Text = ""
TextBox2.Text = ""
TexBox3.Text = ""

End Sub
 
Well that SaveData method has absolutely nothing to do with any TextBoxes so why would they have any affect on it? Also, you aren't passing any parameters to Update so that code couldn't possibly even compile.
 
going on from mr mcilhinney's post, why dont you actually set the parameters on the query and run the query:

Private Sub SaveData()

daPeoplesData.UpdateCommand.Parameters.Item("Perso nID").Value = Text1.Text
daPeoplesData.UpdateCommand.Parameters.Item("Age").Value = Text2.Text
daPeoplesData.UpdateCommand.Parameters.Item("Height").Value = Text3.Text
daPeoplesData.UpdateCommand.ExecuteNonQuery()

End Sub
 
Back
Top