Solved

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

Posted on 2007-04-04
4
1,332 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:EricChristianson
  • 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:EricChristianson
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:EricChristianson
ID: 18869664
Beauty - Thank you sir.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wpf develop 5 32
C# DataGridView_RowsAdded event not firing 1 38
Achieve json result 2 29
Unable  to create new object 9 22
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now