Solved

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

Posted on 2007-04-04
4
1,348 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

734 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