Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a table called tbllogin which has three columns username,password and Forrmname(which is of varchar type).I have a stored procedure which returns Formname based on UN and PWD.So i need to Show the form reurned byu the user.Please suggest me how to do this.


Regards
Chaithanya M
Posted

1 solution

Hi Chaithanya,

Why not make use of reflection? Have a look at the following:
Reflection (C# Programming Guide)
Reflection in C# Tutorial[^]

[UPDATE]

Okay, I have created two forms. From form1 I will make use of Reflection to call form2. Make use of the fully qualified name of the form. Thus, your proc must return the fully qualified name...

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        Assembly assem = Assembly.GetEntryAssembly();
        Form createInstance = (Form)Activator.CreateInstance(assem.GetType("WindowsFormsApplication1.Form2"));
        createInstance.ShowDialog();
    }
}


[UPDATE]

Kind regards,
 
Share this answer
 
v2
Comments
M.CHAITHANYA 19-May-11 2:47am    
Hi,

I Have forms already created in my project .I just wanted to show them by pulling the formname from the database based on username and password
Programm3r 19-May-11 3:30am    
I have updated the solution...
M.CHAITHANYA 19-May-11 8:17am    
Hi,
-Will GetType method of assembly searches for the object provided by us?if so,will it implicitly casts to object type first and starts checking.?
-"CreateInstance"-the name some sounds like it is going to create another instance ,will thsi happen really.what exactly this method do?

Please comment on this.
Programm3r 19-May-11 9:16am    
Hi,

Point #1:
---------

Yes, GetType gets the Type object with the specified name in the assembly instance.

The GetType() function is marked with the special attribute [MethodImpl(MethodImplOptions.InternalCall)]. This means its method body doesn't contain IL but instead is a hook into the internals of the .NET CLR. In this case, it looks at the binary structure of the object's metadata and constructs a System.Type object around it.

As far as I know, [MethodImpl(MethodImplOptions.InternalCall)] should be considered "magic" - you can't hook your own unmanaged code up to new functions with this attribute.

Point #2:
--------

"CreateInstance" -> Creates an instance of the specified type using that type's default constructor. Read more: http://msdn.microsoft.com/en-us/library/wccyzw83.aspx

Hope this answers your question...
Kind regards,
M.CHAITHANYA 19-May-11 9:32am    
hi,
What exactly is creating an instance here.As the Form already exists,there is no need to create an instance right?

Regards
Chaithu

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900