By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Text box Has Changes

P: n/a
I have a simple form where I am using a dataset called Client. On the data
entry screen, there are name, address, city state and zip.

I have the fields bound to the dataset field. (Properties screen: Data
bindings then Text )

When I run the program and make a change to an existing record in the City
text box, the Dataset value for this column is changed as expected. When I
check the HasChanges property it says false. I don't understand why!

Seems I am missing something here. Because when I try to update the
database, it isn't taking the changes. I think it must have something to do
with how I have the text box is binding to the dataset. Is the data binding
process correct using the Text property field? Should I be going to the
Data Binding Tag property? Do I set both the Data Binding Tag and Text?
Are there other properties I need to set?

Any suggestions?

Thanks in advance.
Lance


Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Lance,

A couple of questions:
1. do the other columns update correctly?
2. are you calling the dataadapter update method?

If you could zip me up some code, I probably could help you solve the
matter.

HTH,

Bernie Yaeger
be*****@cherwellinc.com
"Lance Geeck" <lg****@cox.net> wrote in message
news:aKK6b.29803$S_.26995@fed1read01...
I have a simple form where I am using a dataset called Client. On the data entry screen, there are name, address, city state and zip.

I have the fields bound to the dataset field. (Properties screen: Data
bindings then Text )

When I run the program and make a change to an existing record in the City
text box, the Dataset value for this column is changed as expected. When I check the HasChanges property it says false. I don't understand why!

Seems I am missing something here. Because when I try to update the
database, it isn't taking the changes. I think it must have something to do with how I have the text box is binding to the dataset. Is the data binding process correct using the Text property field? Should I be going to the
Data Binding Tag property? Do I set both the Data Binding Tag and Text?
Are there other properties I need to set?

Any suggestions?

Thanks in advance.
Lance

Nov 20 '05 #2

P: n/a
HI Bernie,

Thanks for responding.

1. None of the textbox fields update. The dbbank1.hasChanges comes up
False. This happens even if the values in the text box have changed and
the dataset shows the change in that column.
2. Here is the code:
************ Code **************************
Public Class frmBankMnt
Inherits System.Windows.Forms.Form
Dim ws As New BanksClient.localhost.BankService
Dim addmntflag As addmntflag 'holds passed values and enum on
adding\mnt

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents DsBank1 As BanksClient.localhost.dsBank
Friend WithEvents btnSave As System.Windows.Forms.Button
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents txtBankName As System.Windows.Forms.TextBox
Friend WithEvents txtContactName As System.Windows.Forms.TextBox
Friend WithEvents txtEmailAddress As System.Windows.Forms.TextBox
Friend WithEvents txtPhoneNbr As System.Windows.Forms.TextBox
Friend WithEvents txtAddress As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents txtFax As System.Windows.Forms.TextBox
Friend WithEvents txtCity As System.Windows.Forms.TextBox
Friend WithEvents txtState As System.Windows.Forms.TextBox
Friend WithEvents txtZip As System.Windows.Forms.TextBox
Friend WithEvents txtLastUpdate As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.DsBank1 = New BanksClient.localhost.dsBank
Me.btnSave = New System.Windows.Forms.Button
Me.btnCancel = New System.Windows.Forms.Button
Me.txtBankName = New System.Windows.Forms.TextBox
Me.txtContactName = New System.Windows.Forms.TextBox
Me.txtEmailAddress = New System.Windows.Forms.TextBox
Me.txtPhoneNbr = New System.Windows.Forms.TextBox
Me.txtFax = New System.Windows.Forms.TextBox
Me.txtAddress = New System.Windows.Forms.TextBox
Me.txtCity = New System.Windows.Forms.TextBox
Me.txtState = New System.Windows.Forms.TextBox
Me.txtZip = New System.Windows.Forms.TextBox
Me.txtLastUpdate = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Label6 = New System.Windows.Forms.Label
Me.Label7 = New System.Windows.Forms.Label
Me.Label8 = New System.Windows.Forms.Label
CType(Me.DsBank1,
System.ComponentModel.ISupportInitialize).BeginIni t()
Me.SuspendLayout()
'
'DsBank1
'
Me.DsBank1.DataSetName = "dsBank"
Me.DsBank1.Locale = New
System.Globalization.CultureInfo("en-US")
'
'btnSave
'
Me.btnSave.Location = New System.Drawing.Point(139, 224)
Me.btnSave.Name = "btnSave"
Me.btnSave.TabIndex = 1
Me.btnSave.Text = "Save"
'
'btnCancel
'
Me.btnCancel.Location = New System.Drawing.Point(275, 224)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.TabIndex = 2
Me.btnCancel.Text = "Cancel"
'
'txtBankName
'
Me.txtBankName.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsBank1, "Bank.BankName"))
Me.txtBankName.Location = New System.Drawing.Point(112, 24)
Me.txtBankName.Name = "txtBankName"
Me.txtBankName.Size = New System.Drawing.Size(368, 20)
Me.txtBankName.TabIndex = 3
Me.txtBankName.Text = ""
'
'txtContactName
'
Me.txtContactName.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsBank1, "Bank.ContactName"))
Me.txtContactName.Location = New System.Drawing.Point(112, 48)
Me.txtContactName.Name = "txtContactName"
Me.txtContactName.Size = New System.Drawing.Size(368, 20)
Me.txtContactName.TabIndex = 4
Me.txtContactName.Text = ""
'
'txtEmailAddress
'
Me.txtEmailAddress.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsBank1, "Bank.EMailAddress"))
Me.txtEmailAddress.Location = New System.Drawing.Point(112, 72)
Me.txtEmailAddress.Name = "txtEmailAddress"
Me.txtEmailAddress.Size = New System.Drawing.Size(288, 20)
Me.txtEmailAddress.TabIndex = 5
Me.txtEmailAddress.Text = ""
'
'txtPhoneNbr
'
Me.txtPhoneNbr.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsBank1, "Bank.PhoneNumber"))
Me.txtPhoneNbr.Location = New System.Drawing.Point(112, 96)
Me.txtPhoneNbr.Name = "txtPhoneNbr"
Me.txtPhoneNbr.Size = New System.Drawing.Size(144, 20)
Me.txtPhoneNbr.TabIndex = 6
Me.txtPhoneNbr.Text = ""
'
'txtFax
'
Me.txtFax.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsBank1, "Bank.Fax"))
Me.txtFax.Location = New System.Drawing.Point(368, 96)
Me.txtFax.Name = "txtFax"
Me.txtFax.Size = New System.Drawing.Size(112, 20)
Me.txtFax.TabIndex = 7
Me.txtFax.Text = ""
'
'txtAddress
'
Me.txtAddress.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsBank1, "Bank.Address"))
Me.txtAddress.Location = New System.Drawing.Point(112, 128)
Me.txtAddress.Name = "txtAddress"
Me.txtAddress.Size = New System.Drawing.Size(368, 20)
Me.txtAddress.TabIndex = 8
Me.txtAddress.Text = ""
'
'txtCity
'
Me.txtCity.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsBank1, "Bank.City"))
Me.txtCity.Location = New System.Drawing.Point(112, 152)
Me.txtCity.Name = "txtCity"
Me.txtCity.Size = New System.Drawing.Size(224, 20)
Me.txtCity.TabIndex = 9
Me.txtCity.Text = ""
'
'txtState
'
Me.txtState.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsBank1, "Bank.State"))
Me.txtState.Location = New System.Drawing.Point(344, 152)
Me.txtState.Name = "txtState"
Me.txtState.Size = New System.Drawing.Size(24, 20)
Me.txtState.TabIndex = 10
Me.txtState.Text = ""
'
'txtZip
'
Me.txtZip.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsBank1, "Bank.Zip"))
Me.txtZip.Location = New System.Drawing.Point(376, 152)
Me.txtZip.Name = "txtZip"
Me.txtZip.TabIndex = 11
Me.txtZip.Text = ""
'
'txtLastUpdate
'
Me.txtLastUpdate.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.DsBank1, "Bank.LastUpdate"))
Me.txtLastUpdate.Location = New System.Drawing.Point(304, 184)
Me.txtLastUpdate.Name = "txtLastUpdate"
Me.txtLastUpdate.TabIndex = 12
Me.txtLastUpdate.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(176, 184)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 13
Me.Label1.Text = "Last Update"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(8, 128)
Me.Label3.Name = "Label3"
Me.Label3.TabIndex = 15
Me.Label3.Text = "Address"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(328, 96)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(32, 23)
Me.Label4.TabIndex = 16
Me.Label4.Text = "Fax"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(8, 96)
Me.Label5.Name = "Label5"
Me.Label5.TabIndex = 17
Me.Label5.Text = "Phone"
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(8, 72)
Me.Label6.Name = "Label6"
Me.Label6.TabIndex = 18
Me.Label6.Text = "E-Mail Address"
'
'Label7
'
Me.Label7.Location = New System.Drawing.Point(8, 48)
Me.Label7.Name = "Label7"
Me.Label7.TabIndex = 19
Me.Label7.Text = "Contact Name"
'
'Label8
'
Me.Label8.Location = New System.Drawing.Point(8, 24)
Me.Label8.Name = "Label8"
Me.Label8.TabIndex = 20
Me.Label8.Text = "Bank Name"
'
'frmBankMnt
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(488, 273)
Me.Controls.Add(Me.Label8)
Me.Controls.Add(Me.Label7)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.txtLastUpdate)
Me.Controls.Add(Me.txtZip)
Me.Controls.Add(Me.txtState)
Me.Controls.Add(Me.txtCity)
Me.Controls.Add(Me.txtAddress)
Me.Controls.Add(Me.txtFax)
Me.Controls.Add(Me.txtPhoneNbr)
Me.Controls.Add(Me.txtEmailAddress)
Me.Controls.Add(Me.txtContactName)
Me.Controls.Add(Me.txtBankName)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnSave)
Me.Name = "frmBankMnt"
Me.Text = "Bank Entry and Editing"
CType(Me.DsBank1,
System.ComponentModel.ISupportInitialize).EndInit( )
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub frmAddMnt_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ws.Credentials = System.Net.CredentialCache.DefaultCredentials
DsBank1.Merge(ws.GetAllBanks)
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
DsBank1.GetChanges()
If DsBank1.HasChanges() Then
ws.Credentials =
System.Net.CredentialCache.DefaultCredentials
Dim diffBank As New BanksClient.localhost.dsBank
'creates a dataset that holds the differences
'diffBank.Merge(DsBank1.GetChanges())
'puts the changes into this new dataset from dsbank1
diffBank = ws.UpdateBank(DsBank1) 'updates through the web
service
DsBank1.Merge(diffBank)
'changes are refreshed on dsbank1 it looks like.
End If

End Sub

Private Sub frmBankMnt_Disposed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Disposed, btnCancel.Click
Me.Dispose()
End Sub

Private Sub txtFax_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles txtFax.TextChanged
Debug.Write("Has changes? " & DsBank1.HasChanges.ToString)
'This always comes up false.
End Sub
End Class
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3

P: n/a
Add this line to your btn_SaveClick handler:

Me.BindingContext(Me.DsBank1, "Bank").EndCurrentEdit()

to make the method look like:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

Me.BindingContext(Me.DsBank1, "Bank").EndCurrentEdit()

DsBank1.GetChanges()
If DsBank1.HasChanges() Then
ws.Credentials = System.Net.CredentialCache.DefaultCredentials()
Dim diffBank As New BanksClient.localhost.dsBank
'creates a dataset that holds the differences
'diffBank.Merge(DsBank1.GetChanges())
'puts the changes into this new dataset from dsbank1
diffBank = ws.UpdateBank(DsBank1) 'updates through the web service()
DsBank1.Merge(diffBank)
'changes are refreshed on dsbank1 it looks like.
End If

End Sub

When you make changes to the data in your TextBox controls, data-binding begins an edit that gets committed automatically when you scroll to a new record using something like this:

Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
If (Me.BindingContext(Me.DsBank1, "Bank").Position > 0) Then
Me.BindingContext(Me.DsBank1, "Bank").Position = Me.BindingContext(Me.DsBank1, "Bank").Position - 1
End If
End Sub

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If (Me.BindingContext(Me.DsBank1, "Bank").Position < Me.BindingContext(Me.DsBank1, "Bank").Count - 1) Then
Me.BindingContext(Me.DsBank1, "Bank").Position = Me.BindingContext(Me.DsBank1, "Bank").Position + 1
End If
End Sub

Without moving to a new record, it looks like the edit is never automatically committed for you, so you'll have to end the current edit manually (which commits your changes to the underlying DataSet) before you check to see if the DataSet has
been changed.

Let me know if that doesn't work for you, ok?

hth,
e-
--
eric knox, VB.Net Team
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #4

P: n/a

Hi Eric,

That solved it. I couldn't figure out why the record wasn't being
commited.

Thanks for the help.

Lance
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5

P: n/a
One additional thing I thought of after I sent this was that you don't need to call DsBank1.GetChanges() stand-alone before calling DsBank1.HasChanges()

Calling GetChanges and passing that to the web-service to do the updating is a good thing to do, but calling it stand-alone and not doing anything with the returned DataSet is just wasted effort.

e-
--
eric knox, VB.Net Team
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: Lance Geeck <lg****@cox.net>
| References: <81*************@cpmsftngxa06.phx.gbl>
| X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
| Subject: Re: Text box Has Changes
| Mime-Version: 1.0
| Content-Type: text/plain; charset="us-ascii"
| Content-Transfer-Encoding: 7bit
| Message-ID: <Oj**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.vb
| Date: Wed, 10 Sep 2003 15:49:03 -0700
| NNTP-Posting-Host: actionjackson133.dsl.frii.net 216.17.147.133
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:136504
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
|
| Hi Eric,
|
| That solved it. I couldn't figure out why the record wasn't being
| commited.
|
| Thanks for the help.
|
| Lance
|
|
| *** Sent via Developersdex http://www.developersdex.com ***
| Don't just participate in USENET...get rewarded for it!
|
Nov 20 '05 #6

P: n/a
That makes sense. I'll change it. It sure is a rough ride going from
VB 6 to .NET.

Thanks for the additional help.

Lance.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.