?
Solved

Form Delegation

Posted on 2004-08-18
12
Medium Priority
?
189 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

770 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