Solved

WinForms, DataSets, and C# - Passing DataSet bewteen two Forms

Posted on 2007-04-04
4
1,351 Views
Last Modified: 2013-11-26
MS Visual Studio 2005, SQL 2005, C#, XP Pro, WinForms

I am an ASP.Net/C# programmer with a WinForms Question:  I have two forms, A and B.  The user navs from Form A to Form B.  In Form B, I retrieve a dataset from SQL, and I give it a name (dsPrint).  The user modifies the dataset via a DataGrid in Form B.  I do not save it to SQL.  The user then returns to Form A to View and Print from the DataSet.

Question: Can you give me an example of how I identify the dsPrint dataset in Form A, so I can bind it, scan through it, etc?



0
Comment
Question by:Eric Christianson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:dungla
ID: 18855034
1. In form A declare a DataSet with your name (ex: myDataSet).
2. In form B make DataSet dsPrint become a property with get like this:
private DataSet dsPrint;
public DataSet PrintData
{
get {return dsPrint;}
}
3. Whenever user return to form A, just retrieve the PrintData from form B
FormB formB = new FormB();
formB.ShowDialog();
myDataSet = formB.PrintData
0
 

Author Comment

by:Eric Christianson
ID: 18858964
Something is wrong.  Your code compiles - but - Here are my results:

Form A
protected DataSet myDataSet;

Form B
private DataSet dsPrint;
..
public DataSet PrintData
{
       get {return dsPrint;}
}

Form A (Print Button method)
formB FormB = new formB();
// FormB.ShowDialog();  (Commented out - no effect on results)
myDataSet = FormB.PrintData;

Problem:  During the Initialization of Form B, I retrieve a dataset that has 3 tables, the first one is empty, the others fill comboboxes.  The user selects several filters and I again retrieve the dataset, this time the first table is full.  The user selects what they want to print via a datagrid with imbedded checkboxes.  I delete the unchecked rows from the dataset, and return to Form A with the modified dataset.  All is good.  When the user presses the Print button on Form A, I run your (two) lines above.  For whatever reason, the data retrieval method on FORM B gets run again, empties out the dataset's first table and returns - overwriting the content modified by the user with an empty table.
I've tried adding code to bypass the data retrieval method in Form B, but this causes additional problems.
What am I missing here?
0
 
LVL 13

Accepted Solution

by:
dungla earned 125 total points
ID: 18862126
I see, so you don't need to create new instance of Form B, just make PrintData become public static variable

Form B
private DataSet dsPrint;
public static DataSet PrintData = null;
// Initialization Form B
... your code here
PrintData = dsPrint;

Form A (Print Button method)
myDataSet = FormB.PrintData;
0
 

Author Comment

by:Eric Christianson
ID: 18869664
Beauty - Thank you sir.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question