Solved

Form Delegation

Posted on 2004-08-18
12
182 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
  • 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 250 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

19 Experts available now in Live!

Get 1:1 Help Now