[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Form Delegation

Posted on 2004-08-18
12
Medium Priority
?
190 Views
Last Modified: 2010-04-15
I have two Forms. In form1 there are two textBoxes, i'm trying to refrence these two textBoxes in Form2. I'm having problem refrencing them. I need to call these two textBoxes inorder to authenticate users. Both these textBoxes have been made public.
Also i have tabPages in form2,from tabPage2, by a click of a button i'm trying to pen tabPage3, but having problem with this too. This is mainly due to authentication problem. Heres the code:

private void button1_Click(object sender, System.EventArgs e)
            {
                  SqlConnection da = new SqlConnection(
                        @"Data Source= xxxxxx;"+
                        "Initial Catalog = xxxx;" +
                        "Network Library=DBMSSOCN;"+
                        "user id =xx;"+
                        "Password=xxxx");
                  da.Open();
            SqlCommand thisCommand = da.CreateCommand();
                  
                  String sQuery = "SELECT Name, LicenseID FROM License WHERE Name = '"+ Form1.textBox1.Text +"' AND LicenseID = '"+ Form1.textBox2.Text +"'";
                  SqlCommand cmd = new SqlCommand(sQuery, da);
                  SqlDataReader dr = cmd.ExecuteReader();
                  if(dr.Read()){
                  tabPage3.Show();
                  label3.Text = dr[ "Name" ].ToString();}
                  da.Close();
            }
What do i need to do inorder to solve this scenario.
Thanks,
Les


0
Comment
Question by:lesmydad
[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
  • 5
  • 4
12 Comments
 
LVL 9

Expert Comment

by:msdixon
ID: 11843341
i would include two string properties in the constructor of the child form. when you open up the form, pass the values of the two text boxes in. saves a lot of trouble. then other forms can also use this child form without difficulty.
0
 
LVL 1

Author Comment

by:lesmydad
ID: 11846921
How would  go about implementing the string properties constructors, i nneed to pasds the value from the parent form to the child form. I'm mainly having problem referncing the event from form1 to form2.
Any script exeample will be apprechiated.
Thanks
0
 
LVL 9

Expert Comment

by:msdixon
ID: 11849194
well, how are you opening form2?

here's some pseudo code...

public class form2
{
   private string _name, _licenseId;
   public form2 (string name, string licenseId)
   {
      _name = name;
      _licenseId = licenseId;
   }
}

now within form1, when you open the second form

form2 frm = new form2(textBox1.Text, textbox2.Text);
// for instance if it's a dialog
frm.ShowDialog();
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:lesmydad
ID: 11851616
Hi msdixon,
With the above code i get an errors, firstly
new Form2 i
s not recognised it gives this error: No overload for method 'Form2' takes '2' arguments
and secondly how do i declare the textBoxes at present i,m doing it like Form1.textBox1.Text , but this gives error of referencing problem. As form1. is not recognised.

If i declkare the textBoxes like this "textBox1.Text", then the compiler does not recognise the attribute as there are'nt any textBoxes in form2.

I'm openning my form like this:

this.Visible = false;
                        Form2 frm = new Form2(textBox1.Text, textBox2.Text);
                        frm.ShowDialog();
                        this.Close();

What i'm mainly trying to do, is get the sql command to recognise the valus from textBoxes in form1 into form2.

Thanks,
Les

0
 
LVL 9

Expert Comment

by:msdixon
ID: 11856469
you need to modify the constructor in form2 with the code i posted

public class Form2...
0
 
LVL 1

Author Comment

by:lesmydad
ID: 11861770
Hi msdixon,
Done what u told me to do, modifing the form2 constructor, still no luck. The same old problems turns up as mentioned beodfre Form1.extboxes.Text are not recognised as its not refrenced and the "new" part of new Form2(textBox1.Text, textBox2.Text); throws an error of:

C:\Documents and Settings\encode\Desktop\WindowsApplication5\Form1.cs(178): No overload for method 'Form2' takes '2' arguments

Any other solutions,recommendations.
Thanks
Les
0
 
LVL 9

Accepted Solution

by:
msdixon earned 1000 total points
ID: 11870268
it's case sensitive, so if you pasted my code, it won't match up to yours. it needs to be:

   public Form2 (string name, string licenseId)
   {
      // set your variable values here
   }
0
 
LVL 1

Author Comment

by:lesmydad
ID: 11879597
Thanks, this function correctly, but having problem with openning tabPage3. From tabPage2 when clicked on a button tabPage3 should open. Both tabPages are on form2, so no delegation is involved. I could open tabPage2 from tabPage3, but vice-versa does not take place.
Any idea why.
Thanks
0
 
LVL 9

Expert Comment

by:msdixon
ID: 12070613
i am interested in the final disposition, i just don't want to write all of his code for him.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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