473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Visibility of an object

I have in a form a SqlConnection and a SqlCommand but I also want to use
them in form shown as DialogForm. I declared the objects as public but I
don't know how to go on.

Thank you.
Nov 16 '05 #1
3 1351
Hi,

You have to pass a reference from the current form to the new form,
something like this:

Form2 f2 = new Form2( this ); // here I pass the reference to the current
form, where the Sql* are declared

f2.ShowDialog();

This is how Form2 looks like
class Form2{
Form1 parent

public Form2( Form1 parent){
this.parent = parent;
}

then in the Form2 you can use

parent.SqlCommand , etc

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Alberto" <al*****@nospam.com> wrote in message
news:uh**************@tk2msftngp13.phx.gbl...
I have in a form a SqlConnection and a SqlCommand but I also want to use
them in form shown as DialogForm. I declared the objects as public but I
don't know how to go on.

Thank you.

Nov 16 '05 #2
I finally did it passing at the constructor of the form2, references to the
connection and command objects.
Thanks anyway.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
escribió en el mensaje news:eV**************@TK2MSFTNGP10.phx.gbl...
Hi,

You have to pass a reference from the current form to the new form,
something like this:

Form2 f2 = new Form2( this ); // here I pass the reference to the current
form, where the Sql* are declared

f2.ShowDialog();

This is how Form2 looks like
class Form2{
Form1 parent

public Form2( Form1 parent){
this.parent = parent;
}

then in the Form2 you can use

parent.SqlCommand , etc

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Alberto" <al*****@nospam.com> wrote in message
news:uh**************@tk2msftngp13.phx.gbl...
I have in a form a SqlConnection and a SqlCommand but I also want to use
them in form shown as DialogForm. I declared the objects as public but I
don't know how to go on.

Thank you.


Nov 16 '05 #3
Hi alberto,

That is also a solution :)

Now, what I advise you is to use a aux class to hold these objects , if you
make this class a singleton it will be MUCH easier to you to use them,
otherwise you will have to pass them around to any other form that you use.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Alberto" <al*****@nospam.com> wrote in message
news:uH*************@TK2MSFTNGP11.phx.gbl...
I finally did it passing at the constructor of the form2, references to the connection and command objects.
Thanks anyway.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
escribió en el mensaje news:eV**************@TK2MSFTNGP10.phx.gbl...
Hi,

You have to pass a reference from the current form to the new form,
something like this:

Form2 f2 = new Form2( this ); // here I pass the reference to the current form, where the Sql* are declared

f2.ShowDialog();

This is how Form2 looks like
class Form2{
Form1 parent

public Form2( Form1 parent){
this.parent = parent;
}

then in the Form2 you can use

parent.SqlCommand , etc

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Alberto" <al*****@nospam.com> wrote in message
news:uh**************@tk2msftngp13.phx.gbl...
I have in a form a SqlConnection and a SqlCommand but I also want to use them in form shown as DialogForm. I declared the objects as public but I don't know how to go on.

Thank you.



Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with...
1
by: lkrubner | last post by:
In the first version of this function, I only test for true or false, on a global var, without limiting that true or false to the id of a particular item. What this meant was that if you were using...
8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
1
by: Mark Denardo | last post by:
I stumbled across a weird problem that I don't seem to understand and was wondering if anyone could help explain why it is occurring: Basically I have set up a client/server application where the...
4
by: gg9h0st | last post by:
i'm a newbie studying php. i was into array part on tutorial and it says i'll get an array having keys that from member variable's name by converting an object to array. i guessed "i can...
8
by: khalprin | last post by:
Hello, I'm trying to create a component that will be used from .net clients and COM clients. I've got an object model that looks something like this: ISystem IRuntime IConfiguration...
3
by: RitualDave | last post by:
This compiles and runs successfully in VS2005: ref class A { private: ~A() { this->!A(); } // private! !A() { } // private! }; ....
11
by: -D- | last post by:
How can I turn the visibility of the xml control on or off? <%@ Control Language="c#" AutoEventWireup="false" Codebehind="TopNavBar.ascx.cs" Inherits="compass.user_controls.TopNavBar"...
5
by: =?UTF-8?B?TWFydGluIFDDtnBwaW5n?= | last post by:
Hello, I´ve a general question about the visibility and modification of an object. I will try to explain it in my code, where I have the problem: DocumentList dList =...
2
by: Jamey Bon | last post by:
I am a C# newbie. I am having a tough time with several issues of scope and visibility. In short, why can't I see any of the elements of Form1 (the base form generated by the "Windows...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.