Bound data doesn't change with dataset.

  • Thread starter Thread starter M K
  • Start date Start date
M

M K

. Reply (E-mail) Forward (E-mail)

Subject: Bound data doesn't change with cleared dataset.
From: "M K" <[email protected]> Sent: 7/8/2003
8:29:42 AM




I have a win form app that has several bound controls
(mostly textbox). When I load a job, the dataSet is
filled, and the controls show the data as I navigate. If I
then go and load a new job (new data) I clear the dataset,
and do a new fill. But the controls still show the old
data. Why is this? What am I missing? The controls are
bound at design time. The data is filled at run time. Here
is how I am doing it:
If Not Me.DsOrder1.Orders Is Nothing Then
Me.DsOrder1.Orders.Clear()
Me.cmdSelOrders.Parameters.Add(New OleDb.OleDbParameter
("?JobId", Me._jobId))
Me.daOrders.Fill(Me.DsOrder1)

Any ideas please? Don't know where to look for info on
this.
 
I really need to get this problem resolved. I am trying to
do what you said. How do you set the control to null? Here
is what I have been doing:

Dim i As Int16

Dim ctrl As Control

Dim ctrlName As String

Dim ctrlField As String

Dim boundFields As New Hashtable

Dim key As String



If Not Me.DsOrder1.Orders Is Nothing Then

Me.DsOrder1.Orders.Clear()

Me.DataGrid1.DataSource = DsOrder1.Orders



For i = 0 To Me.BindingContext.Item
(DsOrder1, "Orders").Bindings.Count - 1

ctrlName = Me.BindingContext.Item
(DsOrder1, "Orders").Bindings.Item(i).Control.Name.ToString

ctrlField = Me.BindingContext.Item
(DsOrder1, "Orders").Bindings.Item
(i).BindingMemberInfo.BindingField

boundFields(ctrlName) = ctrlField

Next

For Each key In boundFields.Keys

For Each ctrl In Me.Controls

If ctrl.Name = key Then

Dim curBinding As Binding = ctrl.DataBindings("Text")

ctrl.DataBindings.Remove(curBinding)

ctrl.DataBindings.Add("Text", DsOrder1, "Orders." &
boundFields(key))

Exit For

End If

Next

Next

End If
 
. Reply (E-mail) Forward (E-mail)

Subject: Bound data doesn't change with cleared dataset.
From: "M K" <[email protected]> Sent: 7/8/2003
8:29:42 AM




I have a win form app that has several bound controls
(mostly textbox). When I load a job, the dataSet is
filled, and the controls show the data as I navigate. If I
then go and load a new job (new data) I clear the dataset,
and do a new fill. But the controls still show the old
data. Why is this? What am I missing? The controls are
bound at design time. The data is filled at run time. Here
is how I am doing it:
If Not Me.DsOrder1.Orders Is Nothing Then
Me.DsOrder1.Orders.Clear()
Me.cmdSelOrders.Parameters.Add(New OleDb.OleDbParameter
("?JobId", Me._jobId))
Me.daOrders.Fill(Me.DsOrder1)

Any ideas please? Don't know where to look for info on
this.

Dear M K

I've tried to replicate your problem (as best I can) and the clear
method works fine. I've tried framework 1.0 and 1.1.

The symptoms seem to suggest that you might be creating a new dataset
or table after you've set up the binding.

i.e. in a statement such as...

myTextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text",
myDataset, "myTable.myColumn"))

myDataSet is passed by value so if you create a new DataSet object and
assign it to the myDataSet variable your data binding is still
referencing the previous DataSet instance.

I'm happy to have a closer look at your problem if you're willing to
email me a simplified copy of your project that exhibits the problem.

To mail me replace "nospam" with "neil" in my email address.

Hope this helps

Regards

Neil Allen
 
I feel slightly foolish over all of this. You ever pound your head
against a wall and realize it was something stupid?

It wasn't so much the refreshing or reseting of the data bindings. All I
really needed to do was to refresh the bindingContext, like this:

:Dim myCurMan As CurrencyManager = CType(Me.BindingContext(DsOrder1,
"Orders"), CurrencyManager)
:myCurMan.Refresh()

What I was doing wrong, and I should have made sure before I assumed,
was not specifying the parameter for my dataAdapter. Note here:

:Me.cmdSelOrders.Parameters.Add(New OleDb.OleDbParameter("?JobId",
Me._jobId))
:Me.daOrders.Fill(Me.DsOrder1)

By simply adding the parameter again, I made 2 parameters for the
dataAdapter. It continued to use the first parameter so I got the same
results.

For right now (since I've lost so much time) I am using this quick and
dirty fix before adding the parameter. I hope to clean it up and improve
it at a later date, but this works.

:If Me.cmdSelOrders.Parameters.Contains("?JobId") Then
:Dim pIndex As Int16 = Me.cmdSelOrders.Parameters.IndexOf("?JobId")
:Me.cmdSelOrders.Parameters.RemoveAt(pIndex)
End If

Hope that helps if anybody runs into a similar problem.

M K
 
Dear Mark

I'm really pleased you fixed the problem. I've lost count of the
number of times I've missed the blindingly obvious.

Regards

Neil Allen
 
Back
Top