refresh ???

  • Thread starter Thread starter Marty
  • Start date Start date
M

Marty

Form1 has controls that are bound to columns in a table.

"New" button on Form1 opens up Form2, which queries user for new record.

After Form2 closes, how do you refresh the data displayed in the controls of
Form1 to reflect the additional record?

Thanks,
Marty
 
Thanks.

But since I had set up Forn1 to query the datasource simply by adding the
datasource to its Data (DataBindings) Text property, I do not know how to do
that.

How would I go about that?

Thanks...
 
Setting the data bindings is not what queries the data. I assume you let VS
write the connection/query code for you. You'll need to locate that code
and call it from the unload of Form2.
 
Hello Marty,
Thanks for Sccott's suggestion.

At beginning, I'd like to check if you are developing Winform Application.
(or WebForm Application?)
I assume your application is developing in Winform project model. If I have
misunderstood, please correct me. Thanks.

Scrrot has provided the correct direction. Setting the data bindings is not
what queries the data. In order to refresh the data, we would have to
modify the underlying dataset/datatable.

I'm not sure how you wrote the connection/query code (is it generated by VS
2005 IDE?). If all codes generated by VS 2005, I think there must be many
components on form1 designer surface. (such as DataSet,
BindingSource,TableAdapter and BindingNavigator).
1) To refresh the new data from underlying database, we would have to use
TableAdapter to fill DataSet.
public void refreshDataSource()
{

this.table_1TableAdapter.Fill(this.adventureWorksDataSet.Table_1);
}
2) If you just want to add new row into the dataset, you could create
AddRow() Method in Form1 class and call this method in Form2's unload event
handler.
public void addNewRow(AdventureWorksDataSet.Table_1Row newRow)
{
this.adventureWorksDataSet.Table_1.AddTable_1Row(newRow);
}

The issue sounds not complex. If you could let me know the actual scenario,
I could provide a sample for you.
Hope this helps
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Wen Yuan and Scott - thanks!

Yes - winform, not webform, code generated by the VS2005 IDE.

I apreciate your quick response. I have a much better understanding of the
"DataSet," "BindingSource," and "TableAdapter," now.

I was able to get Form1 to refresh by putting a tableAdapter.Fill() after
the modal call to Form2

private void NewButton_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.ShowDialog();
this.tableAdapter.Fill(this.dataSet.tablename);
}

Hopefully, there is no problem with calling tableAdapter.Fill repeatedly??

Thanks,
Marty
 
Hello Marty,
Thanks for your reply.

I'm glad our suggestion is helpful.
As far as I know, using TableAdapter to fill the underlying table
repeatedly will not cause the runtime exception. However, fill method
implement opens the database connection and retrieve the data from
underlying database. If you call this method repeatedly, this behavior may
cause some performance issue.

Hope this helps.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Marty,

How are you. This is Wen Yuan again. I just want to check if there is
anything we can help with.
If you still have anything unclear or meet any further issue, please feel
to post it here.
We are glad to assist you.

Have a great day,
Sincerely,
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top