Reputation: 351
I'm hoping someone has come across this same predicament I've encountered. I'm developing a .NET 2.0 Winforms application and am trying to exchange an ADO.NET datatable object between two different winforms.
I've got a button on form1 that when clicked, instantiates a different form object and shows it modally. The second modal form allows the user to run some search criteria and bring back an ado.net datatable of search results.
When the user closes the modal form, I want the Datatable of search results to get passed back into the original form, but as I'm stepping through the code, I'm seeing the original empty datatable.
So the second form has a custom constructor where I am trying to pass in the datatable that I am interested in exchanging between both forms.
My understanding is that when you pass an object in as a parameter into a function or constructor, you are in the "by reference" mode and you are manipulating the original contents of the object? But that is not what seems to be happening here. Any insight would be much appreciated.
thanks in advance.
// button click handler code in Form1
DataTable searchResults = new DataTable();
Search searchForm = new Search(this.DropdownDataset, searchResults);
searchForm.ShowDialog(this);
// custom winform constructor code in Form2
public Search(DataSet dropdownData, DataTable searchResults)
{
this.InitializeComponent();
this._dropdownData = dropdownData;
this._lidSearch = new LIDSearch();
this._searchResults = searchResults;
}
Upvotes: 3
Views: 1791
Reputation: 1503290
Passing by reference isn't quite the same as passing a reference by value, but in this case I don't think you'll need to worry about it.
You haven't shown how you're trying to "fetch" the search results afterwards. So far it looks okay, but if you could show the "passing back" part that would help. A short but complete example (e.g. just adding a dummy record to the DataTable
) would help even more.
Upvotes: 1