Showing posts with label share. Show all posts
Showing posts with label share. Show all posts

Friday, March 23, 2012

Refresh a windows form without closing it

Hi all

I have a couple of windows forms which share tables or parts of tables.

When I edit a tables data on one form (form2), where it ,s data is linked to another form ( form1), when I go back to form1 I find that the fields have not been updated until I close the form and reopen it.

Is there a way to refresh the field on form1 by using a button in the menu bar and what would the code behind look like. I use vb .

Thanks

Rob

You can create a button and then in the click event use:

me.refresh which will refresh the whole form, or you can do controlname.refresh which will refresh just the specific control.

|||

Hi

Thanks for your help so far. I have tried the "me. refresh ()" but nothing happens.

I have also added a few things ( as below) to the code to try and get my dataset to refresh , but still without succsess . Can you suggest any other code snippit which I can add to the me.refresh() which would refresh the data in the client dataset.

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

Me.Refresh = ProjectManagmentDataSet1.Client()

End Sub

Thanks

Rob

|||You need to re-fill the dataset. If you are using a table adapter, it would be like the following:

Code Snippet

Me.MyTableAdapter.Fill(Me.MyDataSet.MyTable)

If you look in the Form_Load event, this is usually where the code is located that will load your data. You can simply copy those steps into the ToolStipButton1_Click event. Once the dataset has been re-filled, use Me.Refresh() to refresh the form. If that doesn't make sense, could you post the code that you are using to load the data into your form?

|||

Thanks for your patience so far

Public Class Form2

Private Sub ClientBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClientBindingNavigatorSaveItem.Click

Me.Validate()

Me.ClientBindingSource.EndEdit()

Me.ClientTableAdapter.Update(Me.ProjectManagmentDataSet1.Client)

Me.SHIPSBindingSource.EndEdit()

Me.SHIPSTableAdapter.Update(Me.ProjectManagmentDataSet1.SHIPS)

End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'TODO: This line of code loads data into the 'ProjectManagmentDataSet1.SHIPS' table. You can move, or remove it, as needed.

Me.SHIPSTableAdapter.Fill(Me.ProjectManagmentDataSet1.SHIPS)

'TODO: This line of code loads data into the 'ProjectManagmentDataSet1.Client' table. You can move, or remove it, as needed.

Me.ClientTableAdapter.Fill(Me.ProjectManagmentDataSet1.Client)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Client.Show()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Form1.Show()

End Sub

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

Me.Refresh()

End Sub

End Class

|||

Can you show me the code for Form1 as well? I think that is where we need to do the updating. If I understand your question correctly, you edit in Form2 and need it to update into Form1 without having to close and re-open Form1.

One other item that is not really a huge thing but you may want to change the ClientBindingNavigatorSaveItem_Click to the following:

Private Sub ClientBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClientBindingNavigatorSaveItem.Click

Try

Me.Validate()

Me.ClientBindingSource.EndEdit()

Me.ClientTableAdapter.Update(Me.ProjectManagmentDataSet1.Client)

Me.SHIPSBindingSource.EndEdit()

Me.SHIPSTableAdapter.Update(Me.ProjectManagmentDataSet1.SHIPS)

Catch ex as Exception

MsgBox("Update Failed: " & ex.ToString)

End Try

End Sub

This will pop up a message box with an explanation as to why the database was not able to be updated if there is a problem updating the data.

|||

This is as far as I have gotten. I edit in form1and hope to refresh form2 without closing and reopening.

I have no problem with updating the data , just the long rout around of closing and reopening forms.

Regards

Rob

|||

OK, the code in form2 should be like the following:

Code Snippet

Public Class Form2

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Call loadData()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Client.Show()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Form1.Show()

End Sub

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

Call loadData()

Me.Refresh()

End Sub

Private Sub loadData()

Me.SHIPSTableAdapter.Fill(Me.ProjectManagmentDataSet1.SHIPS)

Me.ClientTableAdapter.Fill(Me.ProjectManagmentDataSet1.Client)

End Sub

End Class

You shouldn't need the "save" part of the code in form2, just in form1. All you need to do is to fill the adapters again and then refresh the form.

|||Thanks ,all sorted out.

Wednesday, March 7, 2012

Redundant Databases

I am trying to architect a system that will will have one or more machines
clustered together. The machines must share a common site database between
them. I assume that one machine at any one time should manage the site
database. If the machine that manages the site database fails, then another
system online, it doesn't matter which, should take over the site manager's
duties. It is acceptable if the first machine online would assume the site
manager's duties initally. The machines are essentually peer to peer, but
someone must manage the common database. Is SQL Server Replication the best
way to do this? Is there other, simpler or better ways to do this?
Database Mirroring or clustering are ideal for this. If you have an
intelligent client which will do automatic failover to the active node Log
Shipping or Clustering will also work.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"dbaechtel" <dbaechtel@.nospam.com> wrote in message
news:F754791D-082E-49C9-A8F6-7A205E9B4083@.microsoft.com...
>I am trying to architect a system that will will have one or more machines
> clustered together. The machines must share a common site database between
> them. I assume that one machine at any one time should manage the site
> database. If the machine that manages the site database fails, then
> another
> system online, it doesn't matter which, should take over the site
> manager's
> duties. It is acceptable if the first machine online would assume the site
> manager's duties initally. The machines are essentually peer to peer, but
> someone must manage the common database. Is SQL Server Replication the
> best
> way to do this? Is there other, simpler or better ways to do this?
|||If you are looking for pure hardware redundancy, clustering is a better
choice. If you want to make the data redundant as well, then you need to go
with an additional technology. In SQL Server 2000 you could use either log
shipping or replication. In SQL Server 2005, you can add database mirroring
to that list.
"dbaechtel" <dbaechtel@.nospam.com> wrote in message
news:F754791D-082E-49C9-A8F6-7A205E9B4083@.microsoft.com...
>I am trying to architect a system that will will have one or more machines
> clustered together. The machines must share a common site database between
> them. I assume that one machine at any one time should manage the site
> database. If the machine that manages the site database fails, then
> another
> system online, it doesn't matter which, should take over the site
> manager's
> duties. It is acceptable if the first machine online would assume the site
> manager's duties initally. The machines are essentually peer to peer, but
> someone must manage the common database. Is SQL Server Replication the
> best
> way to do this? Is there other, simpler or better ways to do this?