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

Here I have ClassA this is a Class file. This class file name now I am saving in Database.

Now I am retrieving the ClassName from Db. And Now I want to create the Object for this class name. Is it Possible?

Regards,

Anilkumar.D
Posted
Updated 28-Nov-11 22:29pm
v2
Comments
RaisKazi 29-Nov-11 4:29am    
Edited: 1) Formatting 2) Spelling Corrections.
RaisKazi 29-Nov-11 4:30am    
This does not looks to be good Application-Design approach.
Anil Honey 206 29-Nov-11 4:44am    
Why so.is there any problem if we use this format.

1 solution

try these lines of code
C#
string str = "System.String";

          object[] parameters = new object[] {dr7["classname"].ToString() };

          object o = System.Activator.CreateInstance(Type.GetType(str),parameters);

createinstance()
 
Share this answer
 
Comments
Anil Honey 206 29-Nov-11 5:01am    
iam getting error object cannot be null value.

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