Solved

Form Delegation

Posted on 2004-08-18
12
183 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
System.Security 2 27
Keyboard 2 34
Need help with a Crystal Report in my C#.Net application 2 16
Calculate number of nights between two dates 5 28
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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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